NUnit.Framework.Constraints.FloatingPointNumerics.AreAlmostEqualUlps Method
Compares two floating point values for equality

Syntax

public static bool AreAlmostEqualUlps (float left, float right, int maxUlps)

Parameters

left
First floating point value to be compared
right
Second floating point value t be compared
maxUlps
Maximum 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

Remarks

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/

Requirements

Namespace: NUnit.Framework.Constraints
Assembly: NUnitLite (in NUnitLite.dll)
Assembly Versions: 0.6.0.0, 1.0.0.0