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

as.integer64.character() should check errno at the C level #17

Open
DavisVaughan opened this issue Mar 26, 2021 · 1 comment
Open

as.integer64.character() should check errno at the C level #17

DavisVaughan opened this issue Mar 26, 2021 · 1 comment

Comments

@DavisVaughan
Copy link
Member

In the case of strings that represent values that are out of the range of representable values by a long long, strtoll() will return LLONG_MAX or LLONG_MIN and set errno to ERANGE.

bit64::as.integer64("12312312423432842390482390482348328992382930482093842384092842834238904823908423904230423908924300")
#> integer64
#> [1] 9223372036854775807

See the Return Value section of:
http://www.cplusplus.com/reference/cstdlib/strtoll/

I imagine that after calling strtoll() here you could check errno, and return NA if it is set to ERANGE (possibly with a warning), which seems like it might be better behavior for R
https://github.com/truecluster/bit64/blob/e428535bc31982d85bc3f4faa1f2ae8481280781/src/integer64.c#L205

@MichaelChirico
Copy link
Collaborator

We are also affected by this -- a side effect is that c.integer64 can cause precision loss, e.g.

c(bit64::as.integer64(1L), "18446744073709551615")
# integer64
# [1] 1                   9223372036854775807

(this from trying to coerce uint64 values to int64)

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

2 participants