diff --git a/composer.json b/composer.json index 8a2de30e..ee507510 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,9 @@ "json-schema/JSON-Schema-Test-Suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, + "suggest": { + "ext-bcmath": "For better number assertion, see issue #588." + }, "extra": { "branch-alias": { "dev-master": "5.0.x-dev" diff --git a/src/JsonSchema/Constraints/TypeConstraint.php b/src/JsonSchema/Constraints/TypeConstraint.php index ff4eba71..af7d774f 100644 --- a/src/JsonSchema/Constraints/TypeConstraint.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -290,8 +290,16 @@ protected function toNumber($value) protected function toInteger($value) { $numberValue = $this->toNumber($value); - if (is_numeric($numberValue) && (int) $numberValue == $numberValue) { - return (int) $numberValue; // cast to number + if (is_numeric($numberValue)) { + if (function_exists('bcsub')) { + if (0 === bcsub((int) $numberValue, $numberValue)) { + return (int) $numberValue; + } + } + + if ((int) $numberValue == $numberValue) { + return (int) $numberValue; // cast to number + } } return $value;