Skip to content
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

Comparison with fixed epsilon in constant float type is wrong #9228

Closed
mvorisek opened this issue Apr 22, 2023 · 3 comments
Closed

Comparison with fixed epsilon in constant float type is wrong #9228

mvorisek opened this issue Apr 22, 2023 · 3 comments

Comments

@mvorisek
Copy link
Contributor

Bug report

0.000123456789123456 type is not the same as 0.000123456789123457.

Float precision fixed in phpstan/phpstan-src#2358.

Related fixes in phpunit:

Code snippet that reproduces the problem

https://phpstan.org/r/d5c58c0a-234f-4d01-b768-210a2ef98eb7

Expected output

described in repro

@phpstan-bot
Copy link
Contributor

@mvorisek After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-36: Dumped type: 0.00012345678912346
-37: Dumped type: 0.00012345678912346
-38: Dumped type: 0.00012345678912346
-41: Parameter #1 $v of method Foo::acceptX() expects 0.00012345678912346, 0.00012345678912346 given.
-42: Parameter #1 $v of method Foo::acceptY() expects 0.00012345678912346, 0.00012345678912346 given.
-43: Parameter #1 $v of method Foo::acceptX() expects 0.00012345678912346, 0.00012345678912346 given.
+36: Dumped type: 0.000123456789123456
+37: Dumped type: 0.000123456789123457
+38: Dumped type: 0.000123456789123456|0.000123456789123457
+41: Parameter #1 $v of method Foo::acceptX() expects 0.000123456789123456, 0.000123456789123457 given.
+42: Parameter #1 $v of method Foo::acceptY() expects 0.000123456789123457, 0.000123456789123456 given.
+43: Parameter #1 $v of method Foo::acceptX() expects 0.000123456789123456, 0.000123456789123456|0.000123456789123457 given.
+44: Parameter #1 $v of method Foo::acceptY() expects 0.000123456789123457, 0.000123456789123456|0.000123456789123457 given.
Full report
Line Error
36 Dumped type: 0.000123456789123456
37 Dumped type: 0.000123456789123457
38 `Dumped type: 0.000123456789123456
41 Parameter #1 $v of method Foo::acceptX() expects 0.000123456789123456, 0.000123456789123457 given.
42 Parameter #1 $v of method Foo::acceptY() expects 0.000123456789123457, 0.000123456789123456 given.
43 `Parameter #1 $v of method Foo::acceptX() expects 0.000123456789123456, 0.000123456789123456
44 `Parameter #1 $v of method Foo::acceptY() expects 0.000123456789123457, 0.000123456789123456

@ondrejmirtes
Copy link
Member

I'd welcome a regression test, but otherwise this is done.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants