opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

multipleOf not working as expected #123

Open nikcani opened 2 years ago

nikcani commented 2 years ago

If you try to validate if the number 400.01 is a multiple of 0.01, you get an error that is not expected.

I have bcmath installed and thus Helper::isMultipleOf is going that way in my setup. Logging shows me that 400.01 is internally handled as 400.00999999999999 and 0.01 is 0.01000000000000, therefore the comparison is between 0 and 0.00999999999999.

I am unsure how to fix this, otherwise, I would have opened a pull request.

Thx upfront for any help :)

MathieM commented 1 year ago

@nikcani I add one PR #126. Dealing with float is not easy in PHP. There's remain some issues.

cc @Flynamic

nikcani commented 1 year ago

Dealing with float is not easy in PHP.

sure, thx for trying

MathieM commented 1 year ago

It's not just a try. It's an improvement and I found others issues with float. But it works better with my fix.

I test firstly if I didn't add any regression. And I can assure you there is no regression

nikcani commented 1 year ago

Thanks for improving :)