views:

1037

answers:

3

Why double.Epsilon != std::numeric_limits<double>::min()?

On my PC: double.Epsilon == 4.9406564584124654E-324 and is defined in .NET std::numeric_limits<double>::min() == 2.2250738585072014e-308

Is there a way to get 2.2250738585072014e-308 from .NET?

+1  A: 

Well you could use C++/CLI to return the value:

double epsilon() { return std::numeric_limits<double>::min(); }

Why would you want to though? Why do they have to be the same? You should try to avoid skating on the edges of your floating point numbers.

1800 INFORMATION
A: 

Epsilon is the minimal possible difference between two doubles. (Edit: not exact, it's the minimal positive nonzero number in this case).

double.MinValue

is what you need.

Yossarian
The OP is looking for a tiny but positive number. double.MinValue is a massive and negative number.
Jon Skeet
Uh? I thought, tnat numeric_limits returns minimal value that can be represented, not minimal nonzero number..
Yossarian
Take a look at the values given in the question: "std::numeric_limits<double>::min() == 2.2250738585072014e-308"
Jon Skeet
+5  A: 

They're different because double.Epsilon returns the smallest representable value. numeric_limits<double>::min() returns the smallest normalized value.

Basically double.Epsilon is the equivalent to numeric_limits<double>::denorm_min().

The easiest way of getting the equivalent in .NET is probably to work out the bit pattern for the minimal normalized number and use BitConverter.Int64BitsToDouble.

Jon Skeet
Exactly the kind of answer I was looking for.Thanks Jon
sthiers