-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Assert: check both relative and absolute error when comparing floats #68
Conversation
What about small floats with opposite sign like |
@milo why? |
@hrach Sorry, I wrote it wrong. I mean, proposed implementation allows such equality and I think it should not. Moreover, on PHP 5.3.6 it is failing: I do not want to be such a bad guy, but it needs just small update :) |
When you put it like this, it it hard to decide. But the idea for The following should be equal if float was "perfect", therefore we intentionally allow numbers like -1e-14, 1e-14 to be equal. $float1 = 1 / 3;
$float2 = 1 - 2 / 3;
Assert::equal($float1 - $float2, $float2 - $float1); |
I'll make the example even better – why should the following have different results? Assert::equal($float1 - $float2 + 123, $float2 - $float1 + 123);
Assert::equal($float1 - $float2, $float2 - $float1); |
And reason why it fails on PHP < 5.4.0 http://3v4l.org/XJdZW |
I changed expectation to make |
OK, it makes sense.
As I rememer university math, two infinities cannot be equal so easily, it depends how quick they are coming to infinity, so I would prefer FALSE. But it is about PHP language vs. math. If no one protests, I would merge that. |
Agreed on your opinion about infinity comparison, however |
Assert: check both relative and absolute error when comparing floats
As it turns out you actually need to check both relative and absolute error 😸