Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: NaN2: Another NaN, an NaN alternative, two types of NaN?
Replies: 8   Last Post: Mar 14, 2009 1:44 AM

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 8,457 Registered: 7/26/08
Re: NaN2: Another NaN, an NaN alternative, two types of NaN?
Posted: Mar 12, 2009 5:04 AM

"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

Date Subject Author
3/12/09 David Painter
3/12/09 Roger Stafford
3/12/09 Roger Stafford
3/12/09 James Tursa
3/12/09 Bruno Luong
3/12/09 James Tursa
3/12/09 Sebastian Hölz
3/12/09 Jos
3/14/09 David Painter