-
Notifications
You must be signed in to change notification settings - Fork 47
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
Comparisons of 0 with 0 rely on integer overflow #148
Comments
Some help here, please @KabooHahahein and @d-meiser. Currently we have the "offending" line
As Do we have an example that exposes this problem in terms of usage? (I understand the "theoretical" problem of overflow here.) |
@thoni56 thanks for looking into this and the analysis. I'll have to have a look at the code to see how |
@thoni56 Here's what I've found so far. The fundamental problem is that we are always doing a relative comparison of the numbers being checked for equality (and similarly in the other constraints). This breaks down for small numbers for fundamental reasons, see e.g. the section "Infernal zero" in https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ The solution is to augment the relative comparison with an absolute comparison. Something like this: bool equal(float a, float b, int significant_figures, float max_diff)
{
if (fabs(a - b) < max_diff) return true;
return max(a, b) - min(a, b) < accuracy(significant_figures, max(fabs(a), fabs(b)));
} I've added our global The problem is that we now need an additional piece of information: If you are OK with this idea I'll go ahead and put together a patch. I'll double check with the boost unit_test framework and gtest to see if this is reasonable. And I'll check what defaults they use for |
Thanks, @d-meiser, sounds like a very good plan! I've just pushed a branch, |
Great, thanks. I'll pull that branch with the additional tests. |
Issue 3 in #135 reported by @KabooHahahein:
First of all, we should not be passing an invalid domain (0) to log10()
Second of all, we should not be casting –Inf to integer then do a subtraction on it. This will cause an overflow.
The text was updated successfully, but these errors were encountered: