[Changeset] Re: Single Precision versus double precision NA

David Bateman adb014 at gmail.com
Thu Jun 5 15:54:52 CDT 2008


David Bateman wrote:
> Jaroslav Hajek wrote:
>> I guess that backward compatibility is not a big issue here because
>> NAs are used much less in Octave than in R (I think Matlab doesn't
>> support them). So I'd vote for changing the value so that the
>> conversion works. If ever R gets single precision, it will face the
>> same issue (and that's going to be more painful, as NAs are heavily
>> used in R).
>>
>> Btw., there are still issues with NaN as well. It seems that both
>> Octave and Matlab do use 0xfff8 0000 0000 0000, i.e. NaN with signbit
>> set. This makes Octave output -NaN instead of NaN in some cases (e.g.
>> NaN*i). Matlab apparently ignores the possibility of signed NaN
>> completely. Some time ago I submitted a patch that makes Octave use
>> the positive NaN as the default (which seems more sensible). It seems
>> it was never applied, presumably because of breaking the compatibility
>> (?)
>>
>>
>>   
> Frankly this is my preferred solution as well. Though the issue of
> existing uses of saved NA values will need to be explicitly taken into
> account. That can easily be done in the isna functions where both the
> old and new values are checked.
> 
> However, I have one issue with doing it in this manner. That is ensuring
> that the double to single conversion of the NA value and visa-versa
> works with the compilers we will be using. I used the code
> 
> include <stdio.h>
> 
> typedef union
> {
>   float value;
>   unsigned int word;
> } lo_ieee_float;
> 
> typedef union
> {
>   double value;
>   unsigned int word[2];
> } lo_ieee_double;
> 
> int main (void)
> {
>   lo_ieee_float vf;
>   lo_ieee_double vd;
>   vf.word = 0x7FC207A2;
>   vd.value = vf.value;
> 
> #ifdef HAVE_LITTLE_ENDIAN
>   if (vd.word[0] != 0x7FF840F4 || vd.word[1] != 0x40000000)
> #else
>   if (vd.word[1] != 0x7FF840F4 || vd.word[0] != 0x40000000)
> #endif
>     printf("ERROR converting single NA to double\n");
>   else
>     printf("single NA to double conversion OK\n");
> 
>   vf.value = vd.value;
> 
>   if (vf.word != 0x7FC207A2)
>     printf("ERROR converting double NA to single\n");
>   else
>     printf("double NA to single conversion OK\n");
> 
>   return (0);
> }
> 
> to test this idea with gcc 4.2.2 on a x86 based machine and the
> conversion worked correctly. However, does this work for other platforms
> and compilers.. It would be good to check as least one Big endian (note
> that the ifdef above should be changed) and the windows platforms..
> Anyone want to run these tests for me?


Ok, then the attached changeset addresses this by changing the NA values
as above. I still have no confirmation that the above code worked as
expected for other machines than my own. However I added a couple of
tests that check that the translation of NA values from single to double
precision and visa-versa is done correctly and so if make check is run
on different systems we'll quickly find if there is an issue with this
change. I also added code to data-conv.cc (read_doubles) to check for
the old NA value and convert it to the new one. So there is forward
compatibility for the NA values saved with older versions of Octave.
However, NA values saved after this change won't be loaded correctly
with older version of Octave. In any case if the conversion in this
changeset works correctly for other platforms, OS and compilers then
this is probably the simplest way to address this issue.

D.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch8213
Url: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080605/079101cc/attachment.ksh 


More information about the Octave-maintainers mailing list