Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.