mo alaz
mo alaz

Reputation: 4759

Double.Epsilon Value

I feel like this should be easy to find somewhere online but I'm having a hard time.

Does anyone know what the c# value is for Double.Epsilon? I'm looking for the exact numerical value.

Upvotes: 0

Views: 3574

Answers (4)

Mark Lakata
Mark Lakata

Reputation: 20878

None of these answers is the exact numerical value. The exact value is a power of 2, namely 2^-1074, as this is how IEEE floating point numbers are actually stored in modern computers. All the other answers given are decimal approximations. If you assign that decimal approximation to a double, then it will round off to 2^-1074, so internally, the register or memory location will receive the true "Epsilon" value. So, using the decimal constant to initial a storage location to the minimum floating point value works, but the decimal constant is still not the actual value of this minimum floating point value.

Explanation: The smallest positive value written in IEEE notation is

0.0000000000000000000000000000000000000000000000000001B x 2^-1022.

(The B is for binary base)

That is a 1 shifted 52 bits to the right of the binary point, then shifted another 1022 bits for a total of 1074 bits. The leading sign bit is zero. Sign bit (1 bit) plus coefficient (52 bits) plus exponent (11 bits) give 64 bits of storage.

Note also this is a "denormalized" floating point value, because the exponent is -1022.

See https://en.wikipedia.org/wiki/IEEE_floating_point and search for "1074".

ps. My calculator gives a more precise representation of the value of Double.Epsilon = 2^-1074 as 4.9406564584124654417656879286822e-324.

Upvotes: 3

kol
kol

Reputation: 28708

MSDN page:

The value of this constant is 4.94065645841247e-324.

Upvotes: 2

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174369

No, this certainly is not correct.

First: The value of Double.Epsilon can easily be found out by either a small program or by reading the documentation:

4.94065645841247E-324

Second: Don't confuse this value with Machine Epsilon which is usually used in comparisons between two double values. See this question for more details on "Machine Epsilon".

Upvotes: 3

Andrei
Andrei

Reputation: 56716

Here is its declaration:

[__DynamicallyInvokable]
public const double Epsilon = 4.94065645841247E-324;

Upvotes: 8

Related Questions