diff options
author | Vincent Pelletier <vincent@nexedi.com> | 2014-12-29 16:21:42 +0100 |
---|---|---|
committer | Vincent Pelletier <vincent@nexedi.com> | 2014-12-29 16:21:42 +0100 |
commit | 2b9a72273edeac33da7d7f9054f676b0e9f37750 (patch) | |
tree | 3a913d91450b822d3c1e4978588e673012921c0e | |
parent | add447fbe562ef07ba36bb8d99a47adc5b9f3044 (diff) | |
download | jsonschema-2b9a72273edeac33da7d7f9054f676b0e9f37750.tar.gz |
Improve mutlipleOf validator with floating point value.
Rely on system's built-in float tolerance by comparing quotient with cast
quotient instead of checking distance to remainder.
-rw-r--r-- | jsonschema/_validators.py | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index 8999e6a..7e5956d 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -5,9 +5,6 @@ from jsonschema.exceptions import FormatError, ValidationError from jsonschema.compat import iteritems -FLOAT_TOLERANCE = 10 ** -15 - - def patternProperties(validator, patternProperties, instance, schema): if not validator.is_type(instance, "object"): return @@ -111,8 +108,8 @@ def multipleOf(validator, dB, instance, schema): return if isinstance(dB, float): - mod = instance % dB - failed = (mod > FLOAT_TOLERANCE) and (dB - mod) > FLOAT_TOLERANCE + quotient = instance / dB + failed = int(quotient) != quotient else: failed = instance % dB |