-
-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multipleOf 0.1 fails for 92.6 #185
Comments
Unfortunately this is just floating points. Those numbers aren't exactly representable as floats, so you're going to get If you need this, you can use decimals. |
@Julian I am aware of how tricky is this business with float numbers. Anyway, current implementation is attempting to get through this problem by introducing some FLOAT_PRECISION and it helps in many cases. I got a feeling, that using some precision relative to the "divisible by" value could bring better results. Using decimals is not the way to go - if I read the data from YAML or JSON, I do not have Decimals at hand at that moment. If the solution for multipleOf is not possible to find, I would understand, if it would be removed from JSON Schema spec, as it is cross-platform present problem. Another thing is - jsonschema is supporting multipleOf - and this is failing in some cases. What to do with this situation? |
Created pull request #186 adding (failing) test case for this issue. |
How can precision help? Once you have the object that you get by typing (or I'm not sure what you mean by decimals not being the way to go because you have JSON or YAML. And about the spec, the spec doesn't specify how to load some JSON -- if you load it in a way that gets you numbers with the precision you need, it works. There's nothing wrong with the spec. (Although maybe someone's brought up the behavior you'll get with floating points, since it's definitely understandably surprising). |
Another library implementing jsonschema has fixed this using the naive approach of "cast floats to Decimals": horejsek/python-fastjsonschema@2aee6eb#diff-dbeb4514cd90df89f7e13c1d897b9b0aR305-R312 Any reason that wouldn't work here? |
It does work here if you load floats into decimals, |
Using jsonschema 2.4.0 my data do not validate if expecting a number to be 92.6 and being
The text was updated successfully, but these errors were encountered: