Where do I find the machine epsilon in C#?

前端 未结 5 1903
暖寄归人
暖寄归人 2020-12-29 08:01

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

There is a Double.Epsilon but t

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 08:25

    It's(on my machine):

       1.11022302462516E-16
    

    You can easily calculate it:

            double machEps = 1.0d;
    
            do {
               machEps /= 2.0d;
            }
            while ((double)(1.0 + machEps) != 1.0);
    
            Console.WriteLine( "Calculated machine epsilon: " + machEps );
    

    Edited:

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

提交回复
热议问题