FloatingPointNumerics Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Helper routines for working with floating point numbers
public class FloatingPointNumerics
type FloatingPointNumerics = class
- Inheritance
-
FloatingPointNumerics
Remarks
The floating point comparison code is based on this excellent article: https://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
"ULP" means Unit in the Last Place and in the context of this library refers to the distance between two adjacent floating point numbers. IEEE floating point numbers can only represent a finite subset of natural numbers, with greater accuracy for smaller numbers and lower accuracy for very large numbers.
If a comparison is allowed "2 ulps" of deviation, that means the values are allowed to deviate by up to 2 adjacent floating point values, which might be as low as 0.0000001 for small numbers or as high as 10.0 for large numbers.
Methods
AreAlmostEqualUlps(Double, Double, Int64) |
Compares two double precision floating point values for equality |
AreAlmostEqualUlps(Single, Single, Int32) |
Compares two floating point values for equality |
ReinterpretAsDouble(Int64) |
Reinterprets the memory contents of an integer value as a double precision floating point value |
ReinterpretAsFloat(Int32) |
Reinterprets the memory contents of an integer as a floating point value |
ReinterpretAsInt(Single) |
Reinterprets the memory contents of a floating point value as an integer value |
ReinterpretAsLong(Double) |
Reinterprets the memory contents of a double precision floating point value as an integer value |