1967
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
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 |
2598
|
34 #if defined (HAVE_NAN_H) |
|
35 #if defined (SCO) |
2560
|
36 #define _IEEE 1 |
2598
|
37 #endif |
2508
|
38 #include <nan.h> |
2598
|
39 #if defined (SCO) |
2560
|
40 #undef _IEEE |
2508
|
41 #endif |
2598
|
42 #endif |
2508
|
43 |
2668
|
44 #if defined (HAVE_INFINITY) |
2702
|
45 extern "C" double infinity (); |
2668
|
46 #endif |
|
47 |
|
48 #if defined (HAVE_QUIET_NAN) |
2702
|
49 extern "C" double quiet_nan (long); |
2668
|
50 #endif |
|
51 |
1967
|
52 #include "lo-ieee.h" |
|
53 |
|
54 // Octave's idea of infinity. |
|
55 double octave_Inf; |
|
56 |
|
57 // Octave's idea of not a number. |
|
58 double octave_NaN; |
|
59 |
|
60 void |
|
61 octave_ieee_init (void) |
|
62 { |
|
63 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
64 |
|
65 // Some version of gcc on some old version of Linux used to crash when |
|
66 // trying to make Inf and NaN. |
|
67 |
2713
|
68 #if defined (SCO) |
|
69 double tmp = 1.0; |
|
70 octave_Inf = 1.0 / (tmp - tmp); |
|
71 #elif defined (__alpha__) |
|
72 extern unsigned int DINFINITY[2]; |
|
73 octave_Inf = (*((double *) (DINFINITY))); |
|
74 #elif defined (HAVE_INFINITY) |
2668
|
75 octave_Inf = infinity (); |
1967
|
76 #elif defined (linux) |
|
77 octave_Inf = HUGE_VAL; |
|
78 #else |
|
79 double tmp = 1e+10; |
|
80 octave_Inf = tmp; |
|
81 for (;;) |
|
82 { |
|
83 octave_Inf *= 1e+10; |
|
84 if (octave_Inf == tmp) |
|
85 break; |
|
86 tmp = octave_Inf; |
|
87 } |
|
88 #endif |
|
89 |
|
90 #endif |
|
91 |
|
92 #if defined (HAVE_ISNAN) |
|
93 |
2713
|
94 #if defined (linux) |
1967
|
95 octave_NaN = NAN; |
|
96 #elif defined (__alpha__) |
|
97 extern unsigned int DQNAN[2]; |
|
98 octave_NaN = (*((double *) (DQNAN))); |
2713
|
99 #elif defined (HAVE_QUIET_NAN) |
|
100 octave_NaN = quiet_nan (0L); |
1967
|
101 #else |
|
102 octave_NaN = octave_Inf / octave_Inf; |
|
103 #endif |
|
104 |
|
105 #endif |
|
106 } |
|
107 |
2508
|
108 #if defined (SCO) |
2560
|
109 |
2508
|
110 extern "C" int |
|
111 isnan (double x) |
|
112 { |
2560
|
113 return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0; |
2508
|
114 } |
|
115 |
|
116 extern "C" int |
|
117 isinf (double x) |
|
118 { |
2560
|
119 return (IsNANorINF (x) && IsINF (x)) ? 1 : 0; |
2508
|
120 } |
2560
|
121 |
2508
|
122 #endif |
|
123 |
1967
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |