-
Notifications
You must be signed in to change notification settings - Fork 286
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
Strange rounding errors with signif and write_csv #1502
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Thanks! Here's a somewhat more minimal reprex: library(readr)
df <- data.frame(x = 1.406148e-20)
df$rounded <- signif(df$x, 4)
cat(format_csv(df))
#> x,rounded
#> 1.4061479999999998e-20,1.4060000000000002e-20 Created on 2023-08-02 with reprex v2.0.2 FWIW these numbers aren't invented, they're just normally not printed: sprintf("%.20e", df$rounded)
#> [1] "1.40600000000000021268e-20" |
Oh, I see. We are hitting the limits of binary representation of a number? Nothing to do with
Still, would be nice to have numbers truncated nicely, just as in the default |
Oh yeah, it's definitely a bug, it will just require some thought to fix because we need to apply some (probably well known) heuristic to avoid accidentally removing decimal places that are important. |
I noticed that certain numbers cause
write_csv
,write_tsv
, etc. to produce strange rounding errors. Here is an example:The content of
test1.csv
file isThe problem seems to be only with
readr
. Thetest2.csv
file is created as expected:I wonder if this is reproducible on other systems.
The text was updated successfully, but these errors were encountered: