[Rd] 1954 from NA
Tomas Kalibera
tom@@@k@||ber@ @end|ng |rom gm@||@com
Sun May 23 18:59:00 CEST 2021
TLDR: tagging R NAs is not possible.
External software should not depend on how R currently implements NA,
this may change at any time. Tagging of NA is not supported in R (if it
were, it would have been documented). It would not be possible to
implement such tagging reliably with the current implementation of NA in R.
NaN payload propagation is not standardized. Compilers are free to and
do optimize code not preserving/achieving any specific propagation.
CPUs/FPUs differ in how they propagate in binary operations, some zero
the payload on any operation. Virtualized environments, binary
translations, etc, may not preserve it in any way, either. ?NA has
disclaimers about this, an NA may become NaN (payload lost) even in
unary operations and also in binary operations not involving other NaN/NAs.
Writing any new software that would depend on that anything specific
happens to the NaN payloads would not be a good idea. One can only
reliably use the NaN payload bits for storage, that is if one avoids any
computation at all, avoids passing the values to any external code
unaware of such tagging (including R), etc. If such software wants any
NaN to be understood as NA by R, it would have to use the documented R
API for this (so essentially translating) - but given the problems
mentioned above, there is really no point in doing that, because such
NAs become NaNs at any time.
Best
Tomas
On 5/23/21 9:56 AM, Adrian Dușa wrote:
> Dear R devs,
>
> I am probably missing something obvious, but still trying to understand why
> the 1954 from the definition of an NA has to fill 32 bits when it normally
> doesn't need more than 16.
>
> Wouldn't the code below achieve exactly the same thing?
>
> typedef union
> {
> double value;
> unsigned short word[4];
> } ieee_double;
>
>
> #ifdef WORDS_BIGENDIAN
> static CONST int hw = 0;
> static CONST int lw = 3;
> #else /* !WORDS_BIGENDIAN */
> static CONST int hw = 3;
> static CONST int lw = 0;
> #endif /* WORDS_BIGENDIAN */
>
>
> static double R_ValueOfNA(void)
> {
> volatile ieee_double x;
> x.word[hw] = 0x7ff0;
> x.word[lw] = 1954;
> return x.value;
> }
>
> This question has to do with the tagged NA values from package haven, on
> which I want to improve. Every available bit counts, especially if
> multi-byte characters are going to be involved.
>
> Best wishes,
More information about the R-devel
mailing list