Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: NaN2: Another NaN, an NaN alternative, two types of NaN?
Date: Thu, 12 Mar 2009 09:04:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 26
Message-ID: <gpaj64$e5a$1@fred.mathworks.com>
References: <gpaejq$heu$1@fred.mathworks.com> <gpagqo$b9e$1@fred.mathworks.com> <gpah4d$183$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236848644 14506 172.30.248.38 (12 Mar 2009 09:04:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Mar 2009 09:04:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:524261

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gpah4d$183$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gpagqo$b9e$1@fred.mathworks.com>...
> > ......
> >   ......  However, you do have the problem of recognizing the difference afterwards.  At the moment I cannot think of a way to do it.
> > ......
> 
> ... except of course by using 'format hex'.
> 
> Roger Stafford

Practical implementation of Roger's remark

% function to generate an NaN of specific type 1, 2, ..., 255
nant = @(type) typecast(uint8([type 0 0 0 0 0 248 255]),'double');

% Function which get the type, 0 if Matlab double or NaN
gettype = @(x) isnan(x).*double(subsref(typecast(x,'uint8'), ...
                                                               substruct('()',{1})));

x1 = nant(1)
x2 = nant(2)

gettype(x1)
gettype(x2)

Bruno