-
Notifications
You must be signed in to change notification settings - Fork 33.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numbersCloseEnoughToEqual function is not valid for all numbers #1549
Comments
If the numbersCloseEnoughToEqual function is not working as expected, it might be due to the limitations of floating-point arithmetic. Floating-point numbers in computers are represented using a finite number of binary digits, which can lead to rounding errors when performing arithmetic operations, especially with numbers that cannot be represented exactly in binary. The example you've provided (2.02 + 1.135 not being equal to 3.155) is a classic illustration of the limitations of floating-point arithmetic. Even though mathematically these two expressions should be equal, due to the way floating-point numbers are represented in binary, the result might not be exactly 3.155. To compare floating-point numbers for "closeness" or "equality," it's often recommended to use a tolerance threshold. You can modify the
|
numbersCloseEnoughToEqual
function is not valid for all numbers.Try this example
Please see snippit in the end of this commet
https://stackoverflow.com/a/56967003
The text was updated successfully, but these errors were encountered: