Machine constants
The MachineConstants class contains constants related to the specific implementation of floating-point arithmetic in the .NET framework and the Common Language Runtime. The System.Single 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 System.Single 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 Double.Epsilon field uses the smallest positive number (roughly 10-308) instead. This makes Double.Epsilon 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 precision | |
---|---|
Represents the machine precision for Double-precision floating point numbers. | |
Represents the square root of the machine precision Epsilon for Double-precision floating point numbers. | |
Represents the cube root of the machine precision Epsilon for Double-precision floating point numbers. | |
Represents the largest possible value of a Double-precision floating point number. | |
Represents the square root of MaxDouble. | |
Represents the natural logarithm of MaxDouble. | |
Represents the smallest Double-precision floating point number that is greater than zero. | |
Represents the square root of MinDouble. | |
Represents the natural logarithm of MinDouble. |
A similar set of constants is available for the Single type.
Machine precision | |
---|---|
Represents the machine precision for Single-precision floating point numbers. | |
Represents the square root of the machine precision SingleEpsilon for Single-precision floating point numbers. | |
Represents the cube root of the machine precision SingleEpsilon for Single-precision floating point numbers. | |
Represents the largest possible value of a Single-precision floating point number. | |
Represents the square root of MaxSingle. | |
Represents the natural logarithm of MaxSingle. | |
Represents the smallest Single-precision floating point number that is greater than zero. | |
Represents the square root of MinSingle. | |
Represents the natural logarithm of MinSingle. |