Skip to content

Commit

Permalink
fix(NumberConstraint): force positive value on first arg
Browse files Browse the repository at this point in the history
Resolves #315 - `multipleOf` is inconsistent, fails for negative numbers
  • Loading branch information
bighappyface committed Oct 10, 2016
1 parent 0bbaac8 commit c669b57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
.settings
composer.lock
docs-api
phpunit.xml
1 change: 1 addition & 0 deletions src/JsonSchema/Constraints/NumberConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function check($element, $schema = null, JsonPointer $path = null, $i = n

private function fmod($number1, $number2)
{
$number1 = abs($number1);
$modulus = fmod($number1, $number2);
$precision = abs(0.0000000001);
$diff = (float)($modulus - $number2);
Expand Down
13 changes: 13 additions & 0 deletions tests/Constraints/NumberAndIntegerTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public function getValidTests()
"type": "object",
"properties": {
"number": {"type": "number"}
}
}'
),
array(
'{"number": -49.89}',
'{
"type": "object",
"properties": {
"number": {
"type": "number",
"multipleOf": 0.01
}
}
}'
)
Expand Down

0 comments on commit c669b57

Please sign in to comment.