octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Single Precision versus double precision NA


From: David Bateman
Subject: Re: Single Precision versus double precision NA
Date: Mon, 02 Jun 2008 17:39:25 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

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?

regards
David




-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]