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
assertSame and assertEquals incorrectly pass on some floats #3159
Comments
i will take it is not true, for numbers, it has epsilon counted in: The thing is, that EPSILON can't be configured. It was introduced in https://github.com/sebastianbergmann/phpunit/pull/273/files#diff-c228e9b2f01ec4a07f0f59042e40ded6R73 , 7 years ago... Docs doesn't match expectations, can you clarify that @sebastianbergmann , it would help clearing the issue. |
ping @sebastianbergmann , can you take a look at this, please ? |
Eventually: yes. This will take time (for thinking and discussing). |
Any news on this?
…--
Kind regards,
Luis Pabon
|
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions. |
Bump? |
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions. |
Bumpey |
This might look like a commun PHP issue with floats ? So not related to PHPUnit. |
Could be, but I don't think so:
|
Its a concrete part of code responsible for this on phpunit level |
The more I think about it the more I come to the conclusion that two floating point numbers cannot (really) be compared for identity and that using I do not remember why
Coming back to |
I think the same As described in the official PHP docs:
|
And this might have been the initial motivation for the hardcoded epsilon value. |
This can be a huge BC breaker on |
The current behavior of |
I've just run up against the same issue. It makes sense to be a little fuzzy at the end of floating point numbers. However, the following test is massively broken:
Ideally, you'd want to ignore the difference from the last few bits in the IEEE 754 representation compared with the maximum of the absolute values, or in other words, the magnitude of the highest exponent should determine the epsilon to use. |
This looks like the first change to introduce EPSILON: 0a952db#diff-25c92442dce593a06a598ee89a3ac318 |
Here is my workaround to compare floating point numbers exactly while still allowing an epsilon/a delta: FloatComparator.php
MyTest.php
Now instead of |
I place my vote here, the epsilon must be relative, Float has precision of 14+ decimal places. Phpunit should check for at least 12 decimal places equality. |
This issue can probably be closed because of #4874. This fix also does not break any backwards-compatibility promises. |
yes - https://3v4l.org/570q1 - and 👍 for the PR! |
Thanks! |
These two assertions pass:
They shouldn't.
The text was updated successfully, but these errors were encountered: