在哪里可以找到在C#中机器精度? [英] Where do I find the machine epsilon in C#?

查看:220
本文介绍了在哪里可以找到在C#中机器精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本机小量的标准地定义为添加到一个最小的数,给出了从一个不同的结果。

The machine epsilon is canonically defined as the smallest number which added to one, gives a result different from one.

有一个双.Epsilon ,但名字很误导性:它是最小的(非正规化)双击价值表示的,因此没用任何一种数字节目。

There is a Double.Epsilon but the name is very misleading: it is the smallest (denormalized) Double value representable, and thus useless for any kind of numeric programming.

我想获得的真正的小量的双击类型,所以不是有硬编码的公差到我的程序。我如何做到这一点。

I'd like to get the true epsilon for the Double type, so that not to have to hardcode tolerances into my program. How do I do this ?

推荐答案

这是(我的机器上):

   1.11022302462516E-16

您可以轻松地计算出它

        double machEps = 1.0d;

        do {
           machEps /= 2.0d;
        }
        while ((double)(1.0 + machEps) != 1.0);

        Console.WriteLine( "Calculated machine epsilon: " + machEps );



编辑:

Edited:

我calcualted 2倍ε,现在应该是正确的。

I calcualted 2 times epsilon, now it should be correct.

这篇关于在哪里可以找到在C#中机器精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆