The MachineConstants class contains constants related to
the specific implementation of floating-point arithmetic in the .NET framework and the Common Language Runtime. The
SystemSingle and Double floating-point types in the
Common Language Specification (CLS) follow the IEEE-754 standard for single and double-precision floating-point
numbers.
Any number representation is necessarily limited. This class provides constants that specify these limits for the
CLS' floating-point types.
Many of these constants are also available in the
SystemSingle and
Double structures.
Unfortunately, these definitions do not follow the standard conventions.
For example, the name epsilon normally refers to
the machine precision. It is equal to the smallest difference between numbers close to unity,
roughly 10-16.
The DoubleEpsilon field
uses the smallest positive number (roughly 10-308) instead.
This makes DoubleEpsilon
completely useless for its intended purpose.
All machine constants are implemented as static fields of the
MachineConstants class.
The following example prints the values of some of the machine constants to the console:
Console.WriteLine("Machine precision: {0:R}", MachineConstants.Epsilon);
Console.WriteLine("Largest value: {0:R}", MachineConstants.MaxDouble);
Console.WriteLine("Smallest normalized value: {0:R}",
MachineConstants.MinNormalizedDouble);
Console.WriteLine("Logarithm of largest value: {0:R}", MachineConstants.LogMaxDouble);
The following table summarizes the machine constants for the
Double type:
Machine constants for the Double data type
Machine precision |
---|
Epsilon | Represents the machine precision for Double-precision floating point numbers. |
SqrtEpsilon |
Represents the square root of the machine precision Epsilon for Double-precision floating point
numbers.
|
CubeRootEpsilon |
Represents the cube root of the machine precision Epsilon for Double-precision floating point
numbers.
|
MaxDouble | Represents the largest possible value of a Double-precision floating point number. |
SqrtMaxDouble |
Represents the square root of MaxDouble.
|
LogMaxDouble |
Represents the natural logarithm of MaxDouble.
|
MinDouble | Represents the smallest Double-precision floating point number that is greater than zero. |
SqrtMinDouble |
Represents the square root of MinDouble.
|
LogMinDouble |
Represents the natural logarithm of MinDouble.
|
A similar set of constants is available for the Single type.
Machine constants for the Double data type.