Support conversion of hexidecimal values#173
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: https://github.com/r-devel/r-svn/blob/c8ab68478c5d2322956e19764c20c092916133cd/src/main/util.c#L2112 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> |
|
Superseded by #228, thanks for the work & discussion which shaped the result! |
This small addition allows
as.integer64.characterto handle hexidecimal printed representation of large integers, in the style ofas.integerin base R.