Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

multipleOf fails with some floats #12

Open
seagreen opened this issue Mar 22, 2014 · 6 comments
Open

multipleOf fails with some floats #12

seagreen opened this issue Mar 22, 2014 · 6 comments

Comments

@seagreen
Copy link
Contributor

Specifically it fails this test:

jsonschema_test.go:56: schema.Validate failed to validate good data.
  file: JSON-Schema-Test-Suite/tests/draft4/multipleOf.json
  test case description: by small number
  schema: {"multipleOf": 0.0001}
  test instance description: 0.0075 is multiple of 0.0001
  test data: 0.0075
  result of schema.Validate:
      expected: true
      actual: false
      actual validation errors: [{Value must be a multiple of 0.0001.}]

One thing I could do is multiple both the operator and the operand by some factor of 10 and then turn them both into integers before making the calculation. No idea if that's a good approach or not.

@titanous
Copy link
Member

So apparently the floating point modulus function is fucked up. It's the same in all languages I've tried.

The solution is to not implement multipleOf for floats, because apparently computers don't know how to do that.

@seagreen
Copy link
Contributor Author

Sounds good. I'll disable multipleOf for floats and make a note in the README.

@seagreen
Copy link
Contributor Author

P.S. I haven't made a note in the README yet, but there's a comment on the multipleOf validator that describes the situation.

@seagreen seagreen reopened this May 30, 2014
@seagreen
Copy link
Contributor Author

Here's how the Python jsonschema package handle's it. Does this look like a good idea: https://github.com/Julian/jsonschema/blob/master/jsonschema/_validators.py#L115

@titanous
Copy link
Member

Yeah, that's an option. I'm entirely unconvinced that multipleOf against floats is meaningful though.

@vlcinsky
Copy link

I found multipleOf meaningful, but the jsonschema solution is definitely not watterproof: python-jsonschema/jsonschema#185

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants