IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
NUnit.Framework.Constraints.FloatingPointNumerics Class Reference

Helper routines for working with floating point numbers More...

Classes

struct  DoubleLongUnion
 Union of a double precision floating point variable and a long More...
 
struct  FloatIntUnion
 Union of a floating point variable and an integer More...
 

Static Public Member Functions

static bool AreAlmostEqualUlps (float left, float right, int maxUlps)
 Compares two floating point _values for equality More...
 
static bool AreAlmostEqualUlps (double left, double right, long maxUlps)
 Compares two double precision floating point _values for equality More...
 
static int ReinterpretAsInt (float value)
 Reinterprets the memory contents of a floating point value as an integer value More...
 
static long ReinterpretAsLong (double value)
 Reinterprets the memory contents of a double precision floating point value as an integer value More...
 
static float ReinterpretAsFloat (int value)
 Reinterprets the memory contents of an integer as a floating point value More...
 
static double ReinterpretAsDouble (long value)
 Reinterprets the memory contents of an integer value as a double precision floating point value More...
 

Private Member Functions

 FloatingPointNumerics ()
 

Detailed Description

Helper routines for working with floating point numbers

The floating point comparison code is based on this excellent article: http://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.

Constructor & Destructor Documentation

NUnit.Framework.Constraints.FloatingPointNumerics.FloatingPointNumerics ( )
inlineprivate

Member Function Documentation

static bool NUnit.Framework.Constraints.FloatingPointNumerics.AreAlmostEqualUlps ( float  left,
float  right,
int  maxUlps 
)
inlinestatic

Compares two floating point _values for equality

Parameters
leftFirst floating point value to be compared
rightSecond floating point value t be compared
maxUlpsMaximum number of representable floating point _values that are allowed to be between the left and the right floating point _values
Returns
True if both numbers are equal or close to being equal

Floating point _values can only represent a finite subset of natural numbers. For example, the _values 2.00000000 and 2.00000024 can be stored in a float, but nothing inbetween them.

This comparison will count how many possible floating point _values are between the left and the right number. If the number of possible _values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

References NUnit.Framework.Constraints.FloatingPointNumerics.FloatIntUnion.Float, NUnit.Framework.Constraints.FloatingPointNumerics.FloatIntUnion.Int, and NUnit.Framework.Constraints.FloatingPointNumerics.FloatIntUnion.UInt.

Referenced by NUnit.Framework.Constraints.Numerics.AreEqual(), NUnit.Framework.Constraints.FloatingPointNumericsTests.DoubleEqualityWithUlps(), and NUnit.Framework.Constraints.FloatingPointNumericsTests.FloatEqualityWithUlps().

static bool NUnit.Framework.Constraints.FloatingPointNumerics.AreAlmostEqualUlps ( double  left,
double  right,
long  maxUlps 
)
inlinestatic

Compares two double precision floating point _values for equality

Parameters
leftFirst double precision floating point value to be compared
rightSecond double precision floating point value t be compared
maxUlpsMaximum number of representable double precision floating point _values that are allowed to be between the left and the right double precision floating point _values
Returns
True if both numbers are equal or close to being equal

Double precision floating point _values can only represent a limited series of natural numbers. For example, the _values 2.0000000000000000 and 2.0000000000000004 can be stored in a double, but nothing inbetween them.

This comparison will count how many possible double precision floating point _values are between the left and the right number. If the number of possible _values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

References NUnit.Framework.Constraints.FloatingPointNumerics.DoubleLongUnion.Double, NUnit.Framework.Constraints.FloatingPointNumerics.DoubleLongUnion.Long, and NUnit.Framework.Constraints.FloatingPointNumerics.DoubleLongUnion.ULong.

static int NUnit.Framework.Constraints.FloatingPointNumerics.ReinterpretAsInt ( float  value)
inlinestatic

Reinterprets the memory contents of a floating point value as an integer value

Parameters
valueFloating point value whose memory contents to reinterpret
Returns
The memory contents of the floating point value interpreted as an integer

References NUnit.Framework.Constraints.FloatingPointNumerics.FloatIntUnion.Float.

Referenced by NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredFloatReinterpretation(), and NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredIntegerReinterpretation().

static long NUnit.Framework.Constraints.FloatingPointNumerics.ReinterpretAsLong ( double  value)
inlinestatic

Reinterprets the memory contents of a double precision floating point value as an integer value

Parameters
valueDouble precision floating point value whose memory contents to reinterpret
Returns
The memory contents of the double precision floating point value interpreted as an integer

References NUnit.Framework.Constraints.FloatingPointNumerics.DoubleLongUnion.Double.

Referenced by NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredDoubleReinterpretation(), and NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredLongReinterpretation().

static float NUnit.Framework.Constraints.FloatingPointNumerics.ReinterpretAsFloat ( int  value)
inlinestatic

Reinterprets the memory contents of an integer as a floating point value

Parameters
valueInteger value whose memory contents to reinterpret
Returns
The memory contents of the integer value interpreted as a floating point value

References NUnit.Framework.Constraints.FloatingPointNumerics.FloatIntUnion.Int.

Referenced by NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredFloatReinterpretation(), and NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredIntegerReinterpretation().

static double NUnit.Framework.Constraints.FloatingPointNumerics.ReinterpretAsDouble ( long  value)
inlinestatic

Reinterprets the memory contents of an integer value as a double precision floating point value

Parameters
valueInteger whose memory contents to reinterpret
Returns
The memory contents of the integer interpreted as a double precision floating point value

References NUnit.Framework.Constraints.FloatingPointNumerics.DoubleLongUnion.Long.

Referenced by NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredDoubleReinterpretation(), and NUnit.Framework.Constraints.FloatingPointNumericsTests.MirroredLongReinterpretation().


The documentation for this class was generated from the following file: