help-octave
[Top][All Lists]
Advanced

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

Re: Difference between NaN and NA?


From: John W. Eaton
Subject: Re: Difference between NaN and NA?
Date: Thu, 8 Apr 2010 07:15:36 -0400

On  8-Apr-2010, Jaroslav Hajek wrote:

| On Thu, Apr 8, 2010 at 9:03 AM, David Bateman <address@hidden> wrote:
| > Jaroslav Hajek wrote:
|
| > Exact.. NaN is flagged by a particular exponent in IEEE754, so there are
| > many values of the mantissa that still give a NaN.

Right, I added this feature to Octave specifically for compatibility
with NA in R.  The idea was to be able to exchange binary data with R
and preserve the special NaN value that R uses for NA.

| In the current situation, NA's do no harm in Octave, but they're also
| not much useful, because most functions ignore them, for instance,
| mean ([1,2,3,NA]) is NA etc.
| On the contrary, inserting checks for NA's everywhere is a good idea
| either, because it will slow things down for everyone.

Yes, I assume R has a lot of special checks for NA (and that you meant
"is not a good idea".  Un?fortunately, no one was ever motivated to
make Octave functions NA-aware.  So the value exists, but it is not
really used for anything.

Also, there is no guarantee that NA will be preserved across a
function call.  For example, on some platforms, you might see
something like

  sin (NA) ==>  NaN

because it might be implemented with something like

  double sin (double x)
  {
    if (isnan (x))
      return NaN;
    ...
  }

instead of

  double sin (double x)
  {
    if (isnan (x))
      return x;
    ...
  }

So even ensuring that NA is preserved would add overhead...

But I still do like the idea of having NA separate from NaN so that
you can have a way to express "missing data" that is separate from
"failed calculation".  But I don't know of any really great way to
implement it.

jwe


reply via email to

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