Summary
Compares two floating point values for equality
- Namespace
- TCLite
.Constraints - Containing Type
- Floating
Point Numerics
Syntax
public static bool AreAlmostEqualUlps(float left, float right, int maxUlps)
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/
Parameters
Name | Type | Description |
---|---|---|
left | float | First floating point value to be compared |
right | float | Second floating point value t be compared |
maxUlps | int | Maximum number of representable floating point values that are allowed to be between the left and the right floating point values |
Return Value
Type | Description |
---|---|
bool | True if both numbers are equal or close to being equal |