-
-
Notifications
You must be signed in to change notification settings - Fork 593
Improve mutlipleOf validator with floating point value. #190
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
Conversation
Rely on system's built-in float tolerance by comparing quotient with cast quotient instead of checking distance to remainder.
Anything wrong with this change ? |
Hey, sorry, been a bit backed up but appreciate the patch certainly. I'm not sure, I have to think about it a bit more. It seems the answer is no, nothing wrong :), because all the tests pass, but I have to look closer since I haven't convinced myself that this actually doesn't just shift the imprecision someplace else. |
Good point, I'm not really sure of this either actually. 150.0 * 2**x
0.00001 + 150.0 * 2**x
|
OK, think you've convinced me for now that this is better than what's there at least, and whenever my brain gets a minute to relax I can try to think a bit harder about it, but merging, appreciated! |
Improve mutlipleOf validator with floating point value.
I'm sorry, I just found a case where my code doesn't work:
I've not yet decided where I wan to go from there. While I understand there is no golden bullet for floats, I would like such "simple" (only 4 significant digits in result...) cases to just work. |
Example:
I've prepared a commit against json-schema/JSON-Schema-Test-Suite adding following test case:
but am not sure it is the right place to put such test nor how to choose "better" values without relying on implementation (does implementatio use modulo ? on double or single precision ? etc). As a result, I could not come up with a meaningful description. Anyway, this test fails with current implementation with:
ValidationError: 150.0 is not a multiple of 0.01
and is fixed with attached patch.