-
-
Notifications
You must be signed in to change notification settings - Fork 215
multipleOf test is invalid #534
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
Comments
how about: 1e308 / 7e307, which is pretty easily calculated by eye to equal = 1.428571... |
No, it's not (at least not that): > 810000007371000067076100610392515554571900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n * 123456789n
100000000000000000000000000000000000000001043629100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n See the This is also the bigint arithmetic, so it's exact. A slimmed down example: > 8100000073710000670761006103925155545719n*123456789n
1000000000000000000000000000000000000000010436291n If the calc in the issue was correct, this should have resolved to |
Sorry, I don't know how to read that. what is |
But here is a simpler explanation that doesn't even deal with long numbers:
|
I believe that whatever check you used just lost the precision somewhere, and the test is correct while the implementation isn't. |
Here is a divison check in js (I did > BigInt('1' + '0'.repeat(317)) % 123456789n
88581385n That's the remainder we got. |
This is what it actually looks like:
Plus a remainder. The lib you are using lost precision somewhere after 131 bits perhaps? (If I got my numbers right). |
aha, I fiddled with my bignum library some more, and got a better result:
|
Given that this test is correct, we should have another multipleOf test that would also normally overflow, but produces a valid result (the quotient is an integer). edit: I no longer agree with this. A test that expects |
I just checked my impl, it passes on the tests that are present here: "schema": {"type": "integer", "multipleOf": 0.4},
"tests": [
{
"data": 1e308,
"valid": true
}
] We should also include that, I think =). Upd: fixed my impl there. |
Also, this seems to fail on my impl: "schema": {"type": "integer", "multipleOf": 3},
"tests": [
{
"data": 1e306,
"valid": false
}
] This happens because I'll think what could be done with that without having to implement arbitrary precision floats which are very slow. |
Yes, there was an internal setting for division accuracy which was defaulting to 40 digits. Now I'm pondering what I should set it to for the edit: actually none of that is necessary :) -- I found a way to get the remainder from the division operation without having to increase the accuracy. All that we care about in |
My original assertion in this issue is false, and I am satisfied that there were no unsolveable issues raised here, so I'm closing. I'll be sending a PR to refine the multipleOf tests to add more combinations and move the overflow test to optional. |
I just added support in my implementation for very very very large numbers, which got the test in optional/float-overflow.json passing, but tickled the final test case in multipleOf.json (which divides 1e308 by 0.123456789) -- I don't see how I can pass both these tests, as either I overflow (which should return valid:false), or I don't overflow, and get valid: true...
because, actually, 1e308 divided by 0.123456789 is an integer:
810000007371000067076100610392515554571900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
see discussion in #438
cc @Zac-HD
The text was updated successfully, but these errors were encountered: