-
Couldn't load subscription status.
- Fork 12
Support conversion of hexidecimal values #173
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
base: main
Are you sure you want to change the base?
Conversation
|
thanks for the PR! the idea seems great! would you mind
|
|
WDYT about just letting |
|
I think the issue with just doing We can easily imagine there's ppl working with long-string identifiers relying on the old behavior. That said, I think we can do this? -ret[i] = strtoll(str, &endpointer, 10);
+int negative=str[0] == '-';
+if (!strncmp(str+negative, "0x", 2) || !strncmp(str+negative,"0X", 2)) {
+ ret[i] = strtoll(str, &endpointer, 16);
+} else {
+ ret[i] = strtoll(str, &endpointer, 10);
+} |
I have tested this code and it yields different behavior in one edge case. I thought I had picked the appropriate behavior, but you can of course correct me. In the case of handling the string "-0x8000000000000000", my original code yielded -9223372036854775807, the first value in the result of I will add the new testing (that includes the handling of input "0") to the PR, and await your decision on the desired behavior for handling "-0x8000000000000000". |
# Conflicts: # tests/testthat/test-integer64.R
|
Let's pick whatever |
|
please add a NEWS entry btw! |
|
I do not think it is possible to match the behavior of How would you like to proceed? |
|
Oh, great point. That's because -922...808 is how Line 28 in 62cd4ee
In fact you've found what I think is kind of buggy behavior in Part of the issue is, there's no 128-bit double to case into with full fidelity to work with these out-of-range values before casting back down to 64 bits; that's what's done in the 32-bit case by R: Anyway, for now, I think we should aim to be consistent between hex & decimal strings, and to bitstrings & return # as.bitstring(lim.integer64())
as.integer64(structure("1000000000000000000000000000000000000000000000000000000000000000", class='bitstring'))
# integer64
# [1] <NA> |
This small addition allows
as.integer64.characterto handle hexidecimal printed representation of large integers, in the style ofas.integerin base R.