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" |
|
49 |
|
50 // Octave's idea of infinity. |
|
51 double octave_Inf; |
|
52 |
|
53 // Octave's idea of not a number. |
|
54 double octave_NaN; |
|
55 |
|
56 void |
|
57 octave_ieee_init (void) |
|
58 { |
|
59 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
60 |
|
61 // Some version of gcc on some old version of Linux used to crash when |
|
62 // trying to make Inf and NaN. |
|
63 |
2713
|
64 #if defined (SCO) |
|
65 double tmp = 1.0; |
|
66 octave_Inf = 1.0 / (tmp - tmp); |
3238
|
67 #elif defined (__alpha__) && ! defined (linux) |
2713
|
68 extern unsigned int DINFINITY[2]; |
3180
|
69 octave_Inf = (*(X_CAST(double *, DINFINITY))); |
1967
|
70 #else |
|
71 double tmp = 1e+10; |
|
72 octave_Inf = tmp; |
|
73 for (;;) |
|
74 { |
|
75 octave_Inf *= 1e+10; |
|
76 if (octave_Inf == tmp) |
|
77 break; |
|
78 tmp = octave_Inf; |
|
79 } |
|
80 #endif |
|
81 |
|
82 #endif |
|
83 |
|
84 #if defined (HAVE_ISNAN) |
|
85 |
3238
|
86 #if defined (__alpha__) && ! defined (linux) |
1967
|
87 extern unsigned int DQNAN[2]; |
3180
|
88 octave_NaN = (*(X_CAST(double *, DQNAN))); |
1967
|
89 #else |
|
90 octave_NaN = octave_Inf / octave_Inf; |
|
91 #endif |
|
92 |
|
93 #endif |
|
94 } |
|
95 |
2508
|
96 #if defined (SCO) |
2560
|
97 |
2508
|
98 extern "C" int |
|
99 isnan (double x) |
|
100 { |
2560
|
101 return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0; |
2508
|
102 } |
|
103 |
|
104 extern "C" int |
|
105 isinf (double x) |
|
106 { |
2560
|
107 return (IsNANorINF (x) && IsINF (x)) ? 1 : 0; |
2508
|
108 } |
2560
|
109 |
2508
|
110 #endif |
|
111 |
1967
|
112 /* |
|
113 ;;; Local Variables: *** |
|
114 ;;; mode: C++ *** |
|
115 ;;; End: *** |
|
116 */ |