-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Add/comment/multipleof #1219
Closed
akshat09867
wants to merge
4
commits into
json-schema-org:main
from
akshat09867:add/comment/multipleof
Closed
Add/comment/multipleof #1219
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the recommendation we want to make?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say "no".
Use of scaled integers is ok but is a choice not a recommendation. And we don't have direct support for a scaled integer - e.g. defining the scale. You push a whole new problem onto consumers.
When it comes to non-integers it isn't really meaningful; why would we be recommending that people only use "particular values". And then there is the problem of representation on all platforms (e.g. 1.3, 2.4, 5.6 cannot be represented precisely as a 32 bit float).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A use case could be defining currency, for example dollars & cents. You'd want to ensure that your data only has a penny ($0.01) resolution.
But the point is that we don't want to force users into a scenario where they should be trying to figure out the nuances of binary float arithmetic while writing their schemas.
I think that the very most, we should be leaving a note that some implementations may use IEEE754 math.
I do think the way that the spec is worded is pretty clever, though.
In C#,
outputs
So following the method prescribed by the spec (using division instead of modulation) actually produces the correct result, even with IEEE754 math.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing monetary values as cents is a good idea, to keep all math as integers, but a better way of specifying that in the schema is with
type: integer
notmultipleOf: 1
.I don't think we want to add anything like
scale
into the spec, though -- this should be defined and controlled by the individual application.We may want to add a note that tooling might implement the
multipleOf
keyword using modulo calculations, as a lead-in to the warning about imprecision with floating point storage.