Skip to content

Commit

Permalink
Use predefined PHP float epsilon
Browse files Browse the repository at this point in the history
Instead of using an arbitrary epsilon, use the predefined PHP constant PHP_FLOAT_EPSILON, which is defined to be the smallest representable positive number "x", such that "x + 1.0 != 1.0".

See https://www.php.net/manual/en/reserved.constants.php#constant.php-float-epsilon for additional information.
  • Loading branch information
marijnvanwezel authored and sebastianbergmann committed Jan 24, 2022
1 parent 6411097 commit 136fae3
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/Framework/Constraint/IsIdentical.php
Expand Up @@ -34,11 +34,6 @@
*/
final class IsIdentical extends Constraint
{
/**
* @var float
*/
private const EPSILON = 0.0000000001;

/**
* @var mixed
*/
Expand Down Expand Up @@ -67,7 +62,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
if (is_float($this->value) && is_float($other) &&
!is_infinite($this->value) && !is_infinite($other) &&
!is_nan($this->value) && !is_nan($other)) {
$success = abs($this->value - $other) < self::EPSILON;
$success = abs($this->value - $other) < PHP_FLOAT_EPSILON;
} else {
$success = $this->value === $other;
}
Expand Down

0 comments on commit 136fae3

Please sign in to comment.