phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Drop wrong float comparison using PHP_FLOAT_EPSILON

Open mvorisek opened this issue 2 years ago • 4 comments

discussion https://github.com/phpstan/phpstan-src/pull/2358#discussion_r1174422409

PHP_FLOAT_EPSILON is small but still much larger than "small floating point values" - https://3v4l.org/570q1

abs($this->value - $type->value) < PHP_FLOAT_EPSILON condition for small numbers always wrongly returned true, === is the only valid cmp as long as both left/right side of the operator are of type float

mvorisek avatar Sep 30 '23 12:09 mvorisek

This pull request has been marked as ready for review.

phpstan-bot avatar Sep 30 '23 12:09 phpstan-bot

These changes need tests to see what they’re sctually fixing.

ondrejmirtes avatar Sep 30 '23 12:09 ondrejmirtes

This pull request has been marked as ready for review.

phpstan-bot avatar Sep 23 '24 07:09 phpstan-bot

TIL that '1e-50' is a numeric string. I guess its super rare, but we might have some logic in the codebase which does not allow - in numeric strings.

staabm avatar Sep 23 '24 08:09 staabm

Thank you.

ondrejmirtes avatar Sep 26 '24 07:09 ondrejmirtes