json-schema-org / website

JSON Schema website
https://json-schema.org
Other
67 stars 177 forks source link

[📝 Docs]: Erroneous example for `multipleOf` #1113

Open Tom-Hubrecht opened 1 week ago

Tom-Hubrecht commented 1 week ago

What Docs changes are you proposing?

The spec of json-schema says that a number x satisfies a multipleOf: m schema when the result of x / m is an integer/ However, in most programming languages, the floating-point numbers are conforming to the ieee754 standard, more precisely, to its binary floating-point specification. In that case, 4.02 is not a multiple of 0.01 (as can be seen in python where float(402) == 4.02 / 0.01 returns False).

The example should be updated to be valid in most programming languages and specify that floating-point multiples are not what they appear to be. For example, 4.2 is a multple of 0.05 according to the spec and when doing the computation in binary floating-points.

Code of Conduct

github-actions[bot] commented 1 week ago

Welcome to the JSON Schema Community. We are so excited you are here! Thanks a lot for reporting your first issue!! 🎉🎉 Please make sure to take a look at our contributors guide if you plan on opening a pull request. For more details, check out the README.md file.

gregsdennis commented 1 week ago

Hey, Tom. Thanks for raising this.

JSON Schema operates on the JSON data model, which uses arbitrary-precision numbers rather than those limited by binary representation. The JSON spec does have a note about considering the practicalities of implementation support, but it's not prescriptive.

As such, we specify multipleOf to work for floating point numbers, and we have tests to ensure implementations support it.

All of that said, I wouldn't see a downside to having a note to your points in the documentation.