-
Notifications
You must be signed in to change notification settings - Fork 2
issue-202 Fix isnearlyequal floating point comparison #104
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
Conversation
f1c13fa to
aae600c
Compare
cedricchevalier19
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fully aware of Magix3D coding style, so some of my remarks may not apply.
I think the comparison can be improved using methods like https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ or https://realtimecollisiondetection.net/blog/?p=89 .
GoogleTest has also some utilities to do this, see https://github.com/google/googletest/blob/3af834740f58ef56058e6f8a1be51f62bc3a6515/googletest/include/gtest/internal/gtest-internal.h#L336 .
Perhaps you may add a unit test directly calling this specific function with your motivating use case (a == 0.0 )^(b == 0.0)?
| static size_t mgxDoubleFixedNotationCharMax; | ||
| #endif // SWIG | ||
|
|
||
| static inline bool isNearlyEqual(const double a, const double b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, constexpr, but it requires implementing it with only one return.
e1599fa to
5d3db59
Compare
5d3db59 to
1ac28b7
Compare
|
Thanks for the insightful feedback |
#33 introduces a bug, where
isNearlyEqual(a, b)returns false when(a == 0) xor (b == 0)(it is an exclusive or), even when the other argument is near zero.We might have to properly investigate further for a more reliable check, but this fix should do in the meantime.
Careful, as it affects the
Utils::Math::Point operator ==it is widely used in all kinds of situations by quite a lot of the methods