Skip to content

multipleOf: support negative values#888

Open
ostrowr wants to merge 1 commit intojson-schema-org:mainfrom
ostrowr:dev/robbie/negative-multipleof
Open

multipleOf: support negative values#888
ostrowr wants to merge 1 commit intojson-schema-org:mainfrom
ostrowr:dev/robbie/negative-multipleof

Conversation

@ostrowr
Copy link
Copy Markdown

@ostrowr ostrowr commented Apr 5, 2026

According to the spec, it's perfectly valid for a negative number to be a multipleOf a positive one:

https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.6.2.1

[6.2.1.](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.6.2.1) multipleOf
The value of "multipleOf" MUST be a number, strictly greater than 0.

A numeric instance is valid only if division by this keyword's value results in an integer.

-4.5/1.5 = -3, which is an integer!

I found this because https://github.com/Stranger6667/jsonschema only admits positive multiples, which I don't think is correct per the spec, but has a 100% pass rate.

Copy link
Copy Markdown
Member

@karenetheridge karenetheridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one! LGTM.

Copy link
Copy Markdown
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looked right according to the spec.

We might consider reducing the positive requirement from multipleOf to just != 0 for the spec. I see no reason it needs to be positive.

@ostrowr
Copy link
Copy Markdown
Author

ostrowr commented Apr 6, 2026

That looked right according to the spec.

We might consider reducing the positive requirement from multipleOf to just != 0 for the spec. I see no reason it needs to be positive.

I think it's marginally simpler to leave it positive since it reduces the space of equivalent schemas. multipleOf: 1 and multipleOf: -1 are equivalent and so I think it's kind of nice to be opinionated about which one to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants