Skip to content

Commit 1b51bd2

Browse files
author
Peter Mead
committed
Simplify the private fmod function
Now that the private fmod function is not using PHP's fmod we can remove the code which was working around it's quirks.
1 parent bd87f30 commit 1b51bd2

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/JsonSchema/Constraints/NumberConstraint.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,13 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $i =
7070

7171
private function fmod($number1, $number2)
7272
{
73-
$number1 = abs($number1);
7473
$modulus = ($number1 - round($number1 / $number2) * $number2);
75-
$precision = abs(0.0000000001);
76-
$diff = (float) ($modulus - $number2);
74+
$precision = 0.0000000001;
7775

78-
if (-$precision < $diff && $diff < $precision) {
76+
if (-$precision < $modulus && $modulus < $precision) {
7977
return 0.0;
8078
}
8179

82-
$decimals1 = mb_strpos($number1, '.') ? mb_strlen($number1) - mb_strpos($number1, '.') - 1 : 0;
83-
$decimals2 = mb_strpos($number2, '.') ? mb_strlen($number2) - mb_strpos($number2, '.') - 1 : 0;
84-
85-
return (float) round($modulus, max($decimals1, $decimals2));
80+
return $modulus;
8681
}
8782
}

0 commit comments

Comments
 (0)