-
Notifications
You must be signed in to change notification settings - Fork 210
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
float, double equality check: clarify functionality #133
Comments
I agree with you that the utility of the floating point equality functions is extremely limited. I would expect one to only use those when the value being checked is being assigned as a constant somewhere, rather than the result of a computation. Because floating point math is imprecise, Check provides additional macros which accept a tolerance for comparisons. These end in https://libcheck.github.io/check/doc/doxygen/html/check_8h.html I see that the fix for the linked bug is switching to these API, which is good: I'm not sure what actions should be done for Check, as the APIs are functioning as expected. One would need to know that using an exact floating point comparison would not be appropriate in most situations. Perhaps the existence of the floating point equality APIs is misleading. However, as there are at least some limited situations where they are needed, I do not think they should be deprecated. If you disagree, please let me know. |
One additional comment, related to the point about Check's testing.
Per my description above there are several Check unit tests which verify that the floating point _eq functions work as expected. Take a look at test_ck_assert_float_with_expr for an example. Below that is the test test_ck_assert_float_eq_tol which verifies the behavior of the _tol asserts, which is likely what most users would use for floating point comparision. |
Thanks a lot for the clarification. I can also only think of better commenting on the functions directly to I just wanted to bring the problem to attention, because I start to think, that not thinking about Currently I see this as a major threat to porting efforts for 32-bit machines (Intel i686, ARM v6/v7): |
Yep. You know what they say about assumptions 😄 . It is easy to make the mistake, even if you are aware of it. |
I didn't mean to be overly snarky. :-) |
Adding a warning to the documentation is easy enough to do, if it can help some user avoid pitfalls. Can you take a look at the following, and see if there is room for improvement? |
This looks good. I realize now, that |
I hear you about reading the header files first, I'll do that sometimes too. The commit I referenced should help close the documentation loop about using the floating point comparison functions when other asserts may be more correct. Thanks for taking a look. In case you need it in the future, the API header documentation is available online here and the documentation you mentioned is available in HTML form here. |
I fail to see that ck_assert_float_eq or ck_assert_double_eq (ck_assert_ldouble_eq) are actually working. For instance:
Comparing two floats this way is simply wrong, see this nice explanation:
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
The text was updated successfully, but these errors were encountered: