Skip to content
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

bignum incorrect conversion #114

Open
minemR opened this issue Apr 18, 2023 · 0 comments
Open

bignum incorrect conversion #114

minemR opened this issue Apr 18, 2023 · 0 comments

Comments

@minemR
Copy link

minemR commented Apr 18, 2023

Using bignum I encountered that portion of numerics (99994999999991:99999999999769) are not converted correctly:

library(openssl)
bignum(99994999999990)
# [b] 99994999999990 # correct
bignum(99994999999991) # + 1
# [b] 100000000000000 # incorrect
bignum(99999999999769) # + 5e+09
# [b] 100000000000000 # incorrect
bignum(99999999999770) # + 1
# [b] 99994999999990 # correct

but, if we use character, conversion is correct:

bignum('99994999999991')
# [b] 99994999999991

Looking at undelaying code we can see that formatC is to be blamed:

formatC(99994999999991, format = "fg")
# [1] "100000000000000"

Maybe this could be fixed replacing formatC with format?

format(99994999999991, scientific = F)
# "99994999999991"
format(99994999999991.11, scientific = F)
# "99994999999991" # should warn?
format(1.13, scientific = F) # "1.13"

Or maybe conversion from double should be turned off and the pitfalls should be described in help?

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

No branches or pull requests

1 participant