Revision 495
(checked in by cbc, 12 years ago)
|
Initial import of Stark code.
|
Line | |
---|
1 |
function x = qnan |
---|
2 |
%QNAN Return a quiet (non-trapping) NaN. |
---|
3 |
% |
---|
4 |
% QNAN is the IEEE arithmetic representation of a quiet (non-trapping) NaN |
---|
5 |
% (Not-a-Number). |
---|
6 |
% |
---|
7 |
% See also NAN, INF. |
---|
8 |
|
---|
9 |
% Author: Peter J. Acklam |
---|
10 |
% Time-stamp: 2002-03-03 13:18:26 +0100 |
---|
11 |
% E-mail: pjacklam@online.no |
---|
12 |
% URL: http://home.online.no/~pjacklam |
---|
13 |
|
---|
14 |
% bit pattern for quiet NaN |
---|
15 |
bitpat = 'fff7ffffffffffff'; |
---|
16 |
u8 = sscanf(bitpat, '%2x'); |
---|
17 |
|
---|
18 |
% name of temporary file |
---|
19 |
file = tempname; |
---|
20 |
|
---|
21 |
% write bit pattern to file as eight uint8 values |
---|
22 |
fid = fopen(file, 'wb'); |
---|
23 |
if fid < 0 |
---|
24 |
error([file ': can''t open file for writing.']); |
---|
25 |
end |
---|
26 |
fwrite(fid, u8, 'uint8'); |
---|
27 |
fclose(fid); |
---|
28 |
|
---|
29 |
% read bit pattern from file as one double value |
---|
30 |
fid = fopen(file, 'rb', 'ieee-be'); |
---|
31 |
if fid < 0 |
---|
32 |
delete(file); |
---|
33 |
error([file ': can''t open file for reading.']); |
---|
34 |
end |
---|
35 |
x = fread(fid, 1, 'double'); |
---|
36 |
fclose(fid); |
---|
37 |
|
---|
38 |
% delete temporary file |
---|
39 |
delete(file); |
---|