-
Notifications
You must be signed in to change notification settings - Fork 40
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
Hardcoded 15 significant digits in num_to_char.c #412
Comments
Can you show us the |
|
OK and now look up the true value of π with 17 digits. |
np, here it is > [1] TRUE |
|
Here is a hint ;) https://www.quora.com/Whats-the-17th-digit-of-pi It may roundtrip, but the digit is not significant in the statistical sense. It is actually wrong in this case, so that is why we don't print it. Anyway I guess we can change it, given that it only appears if users explicitly use |
it is not said by standard that different decimal representation won't be the same in binary, rather it is said that 17 digits is minimum necessary number of significant digits to represent a floating point number with 53 bits mantisa in decimal representation |
Yes I understand it very well :) The question is: do we want a json string that is an accurate representation of the real number (pi in this case) or of the float value approximating that number (including the inaccurate noise part)? As a statistician I am inclined to the former, and and consider the 17th digit insignificant, because it is not accurate. |
but the same may happen with 0.1 simpy. there is no exact representation in binary form of this simple decimal number. |
Then the problem appears the other way around, with 17 digits we can no longer convert the decimal to binary and back. x <- "[3.1415926535897931]"
toJSON(fromJSON(x), digits = I(17)) Anyway it's fine by me, can you send a PR with your change? |
you use perhaps your original package that takes min between 15 and precision.
another exmple of why we should not believe decimal represenation of binary number is below: (quite obvious)
as for PR - I'll do |
@jeroen I'm guessing this issue should be closed now that the PR is in. Relatedly, the help string for |
@cat-zeppelin your change has caused some breakage. Can you please fix #420 ? |
Accordingly to Standard for Floating-Point Arithmetic (IEEE754) if a double-precision number converted to string with 17 significant digits and then converted back to double-precision representation, the final result must match the original number.
But unfortunatelly in numerous places in num_to_char.c (e.g. row 30
int sig_digits = signif ? ceil(fmin(15, precision)) : 0;)
) the number of significant digits limited to 15, so that it is impossible to serialize a double precision number to json and deserialize it to the original value.
The current implementation returns FALSE for the simple check
I've rebuilt the package locally with fixed 15 to 17 in num_to_char.c, and now it works as it must work. This code returns TRUE
The text was updated successfully, but these errors were encountered: