Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
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
|
|
|
|