Is Math.Abs ​​(x) <double.Epsilon equivalent to Math.Abs ​​(x) == 0d?

After a short reading of the light in this article aroused my interest:

I would think that yes, these two statements are equivalent, given the MSDN instruction:

Represents the smallest positive double value that is greater than zero. This field is permanent.

Curious to see what people think.

EDIT: Found a computer with VS and performed this test. It turns out that yes, as expected, they are equivalent.

    [Test]
    public void EpsilonTest()
    {
        Compare(0d);
        Compare(double.Epsilon);
        Compare(double.Epsilon * 0.5);
        Compare(double.NaN);
        Compare(double.PositiveInfinity);
        Compare(double.NegativeInfinity);
        Compare(double.MaxValue);
        Compare(double.MinValue);
    }

    public void Compare(double x)
    {
        Assert.AreEqual(Math.Abs(x) == 0d, Math.Abs(x) < double.Epsilon);
    }
+1
source share
4 answers

The IL code seems to cover this a bit.

Epsilon - , 1, 0, 0. Zero - , 0, 0, 0.

http://en.wikipedia.org/wiki/IEEE_754-1985 , , (x < 1) (x == 0).

, , = 0, = 0 ( , Math.Abs)?

+4

, , . , , .

, double.NaN, PositiveInfinity .., . , double.NaN false.

+1

, "" , .

, .NET double.Epsilon 0d, , . :

var d1 = 0d;
var d2 = double.Epsilon * 0.5;
Console.WriteLine("{0:r} = {1:r}: {2}", d1, d2, d1.Equals(d2));
// Prints: 0 = 0: True

, - x, , double.Epislon, , Abs(x) Abs(0), , == 0d.

, .NET : , , double.Epsilon, .

, "", . , 4.94065645841247E-324 * 0.5 , 2.470328229206235e-324. , , , - #.

double.Epsilon , , , Abs(x) == 0d , double.Epison, # , ; , .

+1

Unfortunately, the statement " Math.Abs(x) < double.Epsilonequivalent Math.Abs(x) == 0d" does not apply to ARM systems at all.

MSDN on Double.Epsilon contradicts itself by stating that

On ARM systems, the value of the Epsilon constant is too small to detect, so it is zero.

This means that on ARM systems there are no non-negative double values ​​less Double.Epsilon, so an expression Math.Abs(x) < double.Epsilonis just another way of saying false.

0
source

All Articles