Coder Social home page Coder Social logo

Comments (8)

brarcher avatar brarcher commented on August 22, 2024

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:

davatorium/rofi@dea962d

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.

brarcher avatar brarcher commented on August 22, 2024

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.

andreasbaumann avatar andreasbaumann commented on August 22, 2024

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.

DaveDavenport avatar DaveDavenport commented on August 22, 2024

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.

andreasbaumann avatar andreasbaumann commented on August 22, 2024

I didn't mean to be overly snarky. :-)
I'm usually the first one to fall into these kind of bugs myself.

from check.

brarcher avatar brarcher commented on August 22, 2024

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?

bf671bf

from check.

andreasbaumann avatar andreasbaumann commented on August 22, 2024

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.

brarcher avatar brarcher commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.