Jump to content

Approximate equality: Difference between revisions

m
Fixed a typo.
m (Thundergnat moved page Approximate Equality to Approximate equality: Follow normal task title capitalization policy)
m (Fixed a typo.)
Line 673:
=={{header|Nim}}==
To compare the floating point values, we use a relative tolerance.
 
 
In order to display the values “a” and “b” as provided, without any rounding, we transmit them as strings to a comparison procedure which compute the floating point values. If the first value “a” is provided as an operation, we use a comparison procedure which accepts the computed value of “a” as second parameter. Here, “b” is never provided as an operation and can always be transmitted as a string.
Line 684 ⟶ 683:
 
proc `~=`(a, b: float): bool =
## Check if "a" and "b" are closedclose.
## We use a relative tolerance to compare the values.
result = abs(a - b) < max(abs(a), abs(b)) * Tolerance
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.