Extreme Optimization >
User's Guide >
Mathematics Library >
General Classes >
Machine Constants
Extreme Optimization User's Guide
User's Guide
Up: General Classes Next: Mathematical Constants Previous: General Classes Contents
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
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 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 the constants to the console:
| C# | Copy Code |
using Extreme.Mathematics;
...
Console.WriteLine("MachineConstants.Epsilon = {0}",
MachineConstants.Epsilon);
Console.WriteLine("MachineConstants.SqrtEpsilon = {0}",
MachineConstants.SqrtEpsilon);
Console.WriteLine("MachineConstants.CubeRootEpsilon = {0}",
MachineConstants.CubeRootEpsilon);
Console.WriteLine("MachineConstants.MaxDouble = {0}",
MachineConstants.MaxDouble);
Console.WriteLine("MachineConstants.SqrtMaxDouble = {0}",
MachineConstants.SqrtMaxDouble);
Console.WriteLine("MachineConstants.LogMaxDouble = {0}",
MachineConstants.LogMaxDouble);
Console.WriteLine("MachineConstants.MinDouble = {0}",
MachineConstants.MinDouble);
Console.WriteLine("MachineConstants.SqrtMinDouble = {0}",
MachineConstants.SqrtMinDouble);
Console.WriteLine("MachineConstants.LogMinDouble = {0}",
MachineConstants.LogMinDouble); |
| Visual Basic | Copy Code |
Imports Extreme.Mathematics
...
Console.WriteLine("MachineConstants.Epsilon = {0}", _
MachineConstants.Epsilon)
Console.WriteLine("MachineConstants.SqrtEpsilon = {0}", _
MachineConstants.SqrtEpsilon)
Console.WriteLine("MachineConstants.CubeRootEpsilon = {0}", _
MachineConstants.CubeRootEpsilon)
Console.WriteLine("MachineConstants.MaxDouble = {0}", _
MachineConstants.MaxDouble)
Console.WriteLine("MachineConstants.SqrtMaxDouble = {0}", _
MachineConstants.SqrtMaxDouble)
Console.WriteLine("MachineConstants.LogMaxDouble = {0}", _
MachineConstants.LogMaxDouble)
Console.WriteLine("MachineConstants.MinDouble = {0}", _
MachineConstants.MinDouble)
Console.WriteLine("MachineConstants.SqrtMinDouble = {0}", _
MachineConstants.SqrtMinDouble)
Console.WriteLine("MachineConstants.LogMinDouble = {0}", _
MachineConstants.LogMinDouble) |
The following table summarizes the machine constants for the Double 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. |
| Largest value |
| 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. |
| Smallest positive value |
| 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. |
Table 1. Machine constants for the Double data type.
A similar set of constants is available for the Single type:
Table 2. Machine constants for the Double data type.
Up: General Classes Next: Mathematical Constants Previous: General Classes Contents
Copyright 2004-2008,
Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M
Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual
Studio.NET, and the Visual Studio Logo are registered trademarks of Microsoft Corporation