1967
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1967
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <cfloat> |
1977
|
28 #include <cmath> |
1967
|
29 |
|
30 #if defined (HAVE_FLOATINGPOINT_H) |
|
31 #include <floatingpoint.h> |
|
32 #endif |
|
33 |
3268
|
34 #if defined (HAVE_IEEEFP_H) |
|
35 #include <ieeefp.h> |
|
36 #endif |
|
37 |
2598
|
38 #if defined (HAVE_NAN_H) |
|
39 #if defined (SCO) |
2560
|
40 #define _IEEE 1 |
2598
|
41 #endif |
2508
|
42 #include <nan.h> |
2598
|
43 #if defined (SCO) |
2560
|
44 #undef _IEEE |
2508
|
45 #endif |
2598
|
46 #endif |
2508
|
47 |
1967
|
48 #include "lo-ieee.h" |
4025
|
49 #include "mach-info.h" |
1967
|
50 |
|
51 void |
|
52 octave_ieee_init (void) |
|
53 { |
|
54 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
55 |
|
56 // Some version of gcc on some old version of Linux used to crash when |
|
57 // trying to make Inf and NaN. |
|
58 |
2713
|
59 #if defined (SCO) |
|
60 double tmp = 1.0; |
|
61 octave_Inf = 1.0 / (tmp - tmp); |
3238
|
62 #elif defined (__alpha__) && ! defined (linux) |
2713
|
63 extern unsigned int DINFINITY[2]; |
3180
|
64 octave_Inf = (*(X_CAST(double *, DINFINITY))); |
1967
|
65 #else |
|
66 double tmp = 1e+10; |
|
67 octave_Inf = tmp; |
|
68 for (;;) |
|
69 { |
|
70 octave_Inf *= 1e+10; |
|
71 if (octave_Inf == tmp) |
|
72 break; |
|
73 tmp = octave_Inf; |
|
74 } |
|
75 #endif |
|
76 |
|
77 #endif |
|
78 |
|
79 #if defined (HAVE_ISNAN) |
|
80 |
3238
|
81 #if defined (__alpha__) && ! defined (linux) |
1967
|
82 extern unsigned int DQNAN[2]; |
3180
|
83 octave_NaN = (*(X_CAST(double *, DQNAN))); |
1967
|
84 #else |
|
85 octave_NaN = octave_Inf / octave_Inf; |
|
86 #endif |
|
87 |
4025
|
88 // This is patterned after code in R. |
|
89 |
|
90 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
|
91 |
|
92 if (ff == oct_mach_info::ieee_big_endian) |
|
93 { |
4072
|
94 lo_ieee_hw = 0; |
|
95 lo_ieee_lw = 1; |
4025
|
96 } |
|
97 else |
|
98 { |
4072
|
99 lo_ieee_hw = 1; |
|
100 lo_ieee_lw = 0; |
4025
|
101 } |
|
102 |
4072
|
103 lo_ieee_double t; |
|
104 t.word[lo_ieee_hw] = LO_IEEE_NA_HW; |
|
105 t.word[lo_ieee_lw] = LO_IEEE_NA_LW; |
4025
|
106 |
|
107 octave_NA = t.value; |
|
108 |
1967
|
109 #endif |
|
110 } |
|
111 |
|
112 /* |
|
113 ;;; Local Variables: *** |
|
114 ;;; mode: C++ *** |
|
115 ;;; End: *** |
|
116 */ |