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
Approx 0 comparison fails #1079
Comments
Anyway, yes the new behaviour is intended. By relative margin the machine epsilon ( |
Ah yes sorry. Of course epsilon is pretty far from 0... But still (just because as of a sudden my tests fail..). Is this also expected behaviour?
|
I just did a test with google's version for float comparisons... which as a test looks (and works) like this:
For this test I extracted the comparison functionality only: The IEEE bit magic is way beyond me but maybe it could be used as inspiration .... |
Fundamentally there are 3 ways of comparing floating point numbers
Approx provides for 1) and 2)*, because these are simpler to work with. We are planning to provide a Matcher for 3)(#1074), and also for 1) because ULP's do not quite work around 0 and denormals either. * Note that we scale by Approx's value, and not by the larger of the two compared values. |
Thanks for the details. I'm testing SIMD (SSE,NEON) code against a scalar CPU version (the truth). It's in the audio domain and values are in I'll probably either go with some version of ULP diff or settle on some sensible margin for the tests. |
@doubleday I found a pretty decent workaround if all of your values are on the scale of ~1. I created a wrapper function around #include <catch2/catch_approx.hpp>
Catch::Approx approx(const double value)
{
return Catch::Approx{ value }.scale(1);
} You can then call this function as follows: CHECK(0.0f == approx(0)); And it should work :) |
To avoid an issue with catch2::Approx defaults applied around 0 See catchorg/Catch2#1079
Description
fails with
I believe this is due to changing the default of
margin
to0
.Is this the intended behaviour?
Changing the margin to default to epsilon fixes this for me:
The text was updated successfully, but these errors were encountered: