I'm not sure what you mean by "equivalent" here, as that's a pretty vague term.
If you mean, will .NET consider any value less than double.Epsilon
to be equal to 0d
, then yes, as the article you linked to clearly demonstrates. You can show this pretty easily:
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
In that sense, if you somehow produce a value of x
that is less than double.Epislon
, it will already be stored in-memory as a zero value, so Abs(x)
will just be Abs(0)
which is, == 0d
.
But this is a limitation of the binary representation as used by .NET to hold floating point numbers: it simply can't represent a non-zero number smaller than double.Epsilon
so it rounds.
That doesn't mean the two statements are "equivalent", because that's entirely context-dependent. Clearly, 4.94065645841247E-324 * 0.5
is not zero, it is 2.470328229206235e-324
. If you are doing calculations that require that level of precision, than no, they are not equivalent -- and you're also out of luck trying to do them in C#.
In most cases, the value of double.Epsilon
is entirely too small to be of any value, meaning that Abs(x)
should == 0d
for values much larger than double.Epison
, but C# relies on you to figure that out; it will happily do the calculations down to that precision, if asked.