Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: NaN2: Another NaN, an NaN alternative, two types of NaN?
Date: Thu, 12 Mar 2009 08:23:52 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <gpagqo$b9e$1@fred.mathworks.com>
References: <gpaejq$heu$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236846232 11566 172.30.248.35 (12 Mar 2009 08:23:52 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Mar 2009 08:23:52 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:524249

"David Painter" <david.ross.painter@gmail.com> wrote in message <gpaejq$heu$1@fred.mathworks.com>...
> Hello,
> 
> I never thought I would find myself asking this, but is there another NaN? I have two sources of NaN values in my program, "incalculable" NaNs (e.g., the answer of NaN - x) and "outlier" NaNs. I want to be able to see them at a glance in an array.
> 
> I thought about using infinity (inf) for the outlier NaNs, but there are no infmean and infstd functions to complement nanmean and nanstd. I really don't want to be creating code to avoid this problem. Is something like the following available?
> 
> a = [1 2 3 NaN 3 4 5 NaN2];
> 
> If not, I would appreciate any one-line solutions: e.g., if(any(inf), ignore it, and nanmean(whatever remains). Inelegant to say the least.
> 
> All the best,
> 
> D

  The IEEE 754 standard allows for many different NaNs if desired in a system.  Any number that starts with hex 7FF... or FFF... and is followed by at least one additional non-zero bit is considered a NaN in the standard.

  In matlab I have found only two different NaNs on my ancient system, 7FF8000000000000 and 7FF8012000000000.  The first of these indicates such things as inf-inf, 0*inf, 0/0, and inf/inf.  The second occurs apparently only with rem(x,0).  I am not sure why this particular operation was selected for a different NaN, but if it still works that way, you could use this for your purposes.  However, you do have the problem of recognizing the difference afterwards.  At the moment I cannot think of a way to do it.

Roger Stafford