Comments (8)
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 _tol
and API details can be found here:
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.
from check.
One additional comment, related to the point about Check's testing.
I would expect a library to write unit tests in to get the concept of floating point comparisions correctly.
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.
from check.
Thanks a lot for the clarification. I can also only think of better commenting on the functions directly to
be very careful with floating point comparisions. A magical function solving all equality tests is not
possible, as it depends on the calculations done and on the range of the floating point numbers used.
I just wanted to bring the problem to attention, because I start to think, that not thinking about
the real nature of floating point data types on computers rises all kind of (future) portability problems.
Currently I see this as a major threat to porting efforts for 32-bit machines (Intel i686, ARM v6/v7):
authors concluding because it's working on their 64-bit Intel laptop at home makes the code correct.
:-)
from check.
Currently I see this as a major threat to porting efforts for 32-bit machines (Intel i686, ARM v6/v7):
authors concluding because it's working on their 64-bit Intel laptop at home makes the code correct.
:-)
Yep. You know what they say about assumptions 😄 . It is easy to make the mistake, even if you are aware of it.
from check.
I didn't mean to be overly snarky. :-)
I'm usually the first one to fall into these kind of bugs myself.
from check.
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?
from check.
This looks good.
I realize now, that doc/check.texi
contains tons of nice documentation about floating point
comparision. I just read the header files instead of the documentation first. :-)
from check.
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.
from check.
Related Issues (20)
- Issue: Not able use Check-C framework with arm-none-eabi-gcc compiler HOT 3
- Question: make subunit dependency explicit HOT 1
- cmake_minimum_required(...) has a wrong version required HOT 2
- Restore scan-build checks for snprintf replacement
- check_check and check_check_export fail on Guix powerpc64le-linux HOT 3
- Glenn Washburn's JUnit patch was never merged back then. What happened? HOT 2
- migrate open SourceForge bugs and features to GitHub
- several potential bugs of NULL Pointer Dereference HOT 3
- Wrong binaries on Windows HOT 2
- Enhancement: Adding Check test discovery for CMake
- Check Installation on Windows 64 Bit HOT 3
- Can't compile on Ubuntu with Codeblocks HOT 1
- Add assert functions for ASCII character
- Add assert functions for wide character and string of wide characters
- Deeper integration in CLion for detailed information HOT 1
- MacOS M1 with brew & CMAKE installation has missing files
- Custom report output HOT 1
- Feedback: it feels like libcheck's default setup is hostile to debuggers
- cmake deprecation warning - policy CMP0076
- Linking error with MSYS2 when compiling with cmake
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from check.