FloatingPointNumerics.

AreAlmostEqualUlps(double, double, long) Method

Summary

Compares two double precision floating point values for equality
Namespace
TCLite.Constraints
Containing Type
FloatingPointNumerics

Syntax

public static bool AreAlmostEqualUlps(double left, double right, long maxUlps)

Remarks

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/

Parameters

Name Type Description
left double First double precision floating point value to be compared
right double Second double precision floating point value t be compared
maxUlps long Maximum number of representable double precision floating point values that are allowed to be between the left and the right double precision floating point values

Return Value

Type Description
bool True if both numbers are equal or close to being equal