Skip to content
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

[📝 Docs]: Erroneous example for multipleOf #1113

Open
1 task done
Tom-Hubrecht opened this issue Nov 13, 2024 · 7 comments · May be fixed by #1206
Open
1 task done

[📝 Docs]: Erroneous example for multipleOf #1113

Tom-Hubrecht opened this issue Nov 13, 2024 · 7 comments · May be fixed by #1206
Assignees
Labels
📝 Documentation Indicates improvements or additions to documentation. good first issue Good for newcomers Status: Available No one has claimed responsibility for resolving this issue.

Comments

@Tom-Hubrecht
Copy link

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

  • I agree to follow this project's Code of Conduct
@Tom-Hubrecht Tom-Hubrecht added Status: Triage This is the initial status for an issue that requires triage. 📝 Documentation Indicates improvements or additions to documentation. labels Nov 13, 2024
Copy link

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
Copy link
Member

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.

@benjagm benjagm assigned gregsdennis and unassigned gregsdennis Nov 23, 2024
@benjagm benjagm added Status: Available No one has claimed responsibility for resolving this issue. good first issue Good for newcomers and removed Status: Triage This is the initial status for an issue that requires triage. labels Nov 23, 2024
@benjagm benjagm moved this to Waiting for Contributions in Website Contributor Board Nov 23, 2024
@inclinedadarsh
Copy link

@gregsdennis this sounds like a pretty good issue to start with. I'd like to attempt it, can you please assign this to me?

Moreover, please tell me if you'd like the example to be updated or to add a note explaining this nitty gritty in a note?

@Tom-Hubrecht can you please link me to the page where you found this issue? That would be really helpful.

Thank you!

@gregsdennis
Copy link
Member

gregsdennis commented Dec 19, 2024

@Tom-Hubrecht these cases actually sound like good candidates for the test suite. Note that the spec does contain section 4.2 which discusses numeric precision.

@inclinedadarsh I don't manage assignments. That's going to be @valeriahhdez primarily. That said, if you do take this, please consider the spec section linked above when working on this. The documentation should clearly state the requirement, and the implications for implementation support should be a note of some kind. I'll leave UX & styling to Valeria's expertise.

@valeriahhdez
Copy link
Contributor

Hello @inclinedadarsh,

Thank you for your interest in this issue. The keywordmultipleOf is documented within our Reference, more specifically here: https://json-schema.org/understanding-json-schema/reference/numeric#multiples

I highly recommend you read our guidelines and style guide. In the latter resource, you will find rules we follow when adding notes and notices to our documentation.

Let me know if you have any questions or you can also send me a DM in our Slack workspace, @Valeria Hernandez.

@Tom-Hubrecht
Copy link
Author

@Tom-Hubrecht these cases actually sound like good candidates for the test suite. Note that the spec does contain section 4.2 which discusses numeric precision.

Putting this example in the test suite is a good idea, but what you will see is that almost none of the existing validators is compliant because the underlying floating point numbers is incompatible with the json standard. (My opinion is that it is a deep flaw in the json spec but well...)

@gregsdennis
Copy link
Member

gregsdennis commented Dec 20, 2024

I willing to bet you'd be surprised. Here's mine (https://json-everyting.net):

image

You may also find my rant/blog post interesting as well.

akshat09867 added a commit to akshat09867/Json_website that referenced this issue Dec 27, 2024
akshat09867 added a commit to akshat09867/Json_website that referenced this issue Dec 27, 2024
akshat09867 added a commit to akshat09867/Json_website that referenced this issue Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 Documentation Indicates improvements or additions to documentation. good first issue Good for newcomers Status: Available No one has claimed responsibility for resolving this issue.
Projects
Status: Waiting for Contributions
Development

Successfully merging a pull request may close this issue.

5 participants