4072
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 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 <float.h> |
|
28 #include <math.h> |
|
29 |
|
30 #if defined (HAVE_FLOATINGPOINT_H) |
|
31 #include <floatingpoint.h> |
|
32 #endif |
|
33 |
|
34 #if defined (HAVE_IEEEFP_H) |
|
35 #include <ieeefp.h> |
|
36 #endif |
|
37 |
|
38 #if defined (HAVE_NAN_H) |
|
39 #if defined (SCO) |
|
40 #define _IEEE 1 |
|
41 #endif |
|
42 #include <nan.h> |
|
43 #if defined (SCO) |
|
44 #undef _IEEE |
|
45 #endif |
|
46 #endif |
|
47 |
|
48 #include "lo-ieee.h" |
|
49 |
4074
|
50 #if defined (_AIX) && defined (__GNUG__) |
|
51 #undef finite |
|
52 #define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX) |
|
53 #endif |
|
54 |
4102
|
55 /* Octave's idea of infinity. */ |
|
56 double octave_Inf; |
|
57 |
|
58 /* Octave's idea of a missing value. */ |
|
59 double octave_NA; |
|
60 |
|
61 /* Octave's idea of not a number. */ |
|
62 double octave_NaN; |
|
63 |
|
64 int lo_ieee_hw; |
|
65 int lo_ieee_lw; |
|
66 |
4072
|
67 #if defined (SCO) |
|
68 |
|
69 int |
|
70 isnan (double x) |
|
71 { |
|
72 return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0; |
|
73 } |
|
74 |
|
75 int |
|
76 isinf (double x) |
|
77 { |
|
78 return (IsNANorINF (x) && IsINF (x)) ? 1 : 0; |
|
79 } |
|
80 |
|
81 #endif |
|
82 |
|
83 int |
4074
|
84 lo_ieee_isnan (double x) |
4072
|
85 { |
4074
|
86 #if defined (HAVE_ISNAN) |
4075
|
87 return isnan (x) ? ! lo_ieee_is_NA (x) : 0; |
4074
|
88 #else |
|
89 return 0; |
|
90 #endif |
4072
|
91 } |
|
92 |
|
93 int |
4074
|
94 lo_ieee_finite (double x) |
4072
|
95 { |
4074
|
96 #if defined (HAVE_FINITE) |
|
97 return finite (x) != 0 && ! lo_ieee_is_NaN_or_NA (x); |
|
98 #elif defined (HAVE_ISINF) |
|
99 return (! isinf (x) && ! lo_ieee_is_NaN_or_NA (x)); |
|
100 #else |
|
101 return ! lo_ieee_is_NaN_or_NA (x); |
|
102 #endif |
|
103 } |
|
104 |
|
105 int |
|
106 lo_ieee_isinf (double x) |
|
107 { |
|
108 #if defined (HAVE_ISINF) |
|
109 return isinf (x); |
|
110 #elif defined (HAVE_FINITE) |
|
111 return (! (finite (x) || lo_ieee_is_NaN_or_NA (x))); |
|
112 #else |
|
113 return 0; |
|
114 #endif |
4072
|
115 } |
|
116 |
4075
|
117 int |
|
118 lo_ieee_is_NA (double x) |
|
119 { |
|
120 lo_ieee_double t; |
|
121 t.value = x; |
|
122 return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0; |
|
123 } |
|
124 |
|
125 int |
|
126 lo_ieee_is_NaN_or_NA (double x) |
|
127 { |
|
128 return lo_ieee_isnan (x); |
|
129 } |
|
130 |
4102
|
131 double |
|
132 lo_ieee_inf_value (void) |
|
133 { |
|
134 return octave_Inf; |
|
135 } |
|
136 |
|
137 double |
|
138 lo_ieee_na_value (void) |
|
139 { |
|
140 return octave_NA; |
|
141 } |
|
142 |
|
143 double |
|
144 lo_ieee_nan_value (void) |
|
145 { |
|
146 return octave_NaN; |
|
147 } |
|
148 |
4072
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |