-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
dotnet/docs
#43345Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-System.Runtimehelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]
Milestone
Description
The example code for IsApproximatelyEqual
in single fails when you pass it negative numbers.
For example:
IsApproximatelyEqual(-10, -0.1)
returns True
This seems to be caused by the divisor
being negative:
double divisor = Math.Max(value1.Value, value2.Value);
if (divisor.Equals(0))
{
divisor = Math.Min(value1.Value, value2.Value);
}
return Math.Abs(value1.Value - value2.Value) / divisor <= epsilon;
Given two negative numbers the divisor is negative and so always <= epsilon
. Testing locally a fix is to Math.Abs(divisor)
or change the return line to:
return Math.Abs((value1.Value - value2.Value) / divisor) <= epsilon;
Metadata
Metadata
Assignees
Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-System.Runtimehelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]