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 |
4072
|
55 #if defined (SCO) |
|
56 |
|
57 int |
|
58 isnan (double x) |
|
59 { |
|
60 return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0; |
|
61 } |
|
62 |
|
63 int |
|
64 isinf (double x) |
|
65 { |
|
66 return (IsNANorINF (x) && IsINF (x)) ? 1 : 0; |
|
67 } |
|
68 |
|
69 #endif |
|
70 |
|
71 int |
4074
|
72 lo_ieee_isnan (double x) |
4072
|
73 { |
4074
|
74 #if defined (HAVE_ISNAN) |
4075
|
75 return isnan (x) ? ! lo_ieee_is_NA (x) : 0; |
4074
|
76 #else |
|
77 return 0; |
|
78 #endif |
4072
|
79 } |
|
80 |
|
81 int |
4074
|
82 lo_ieee_finite (double x) |
4072
|
83 { |
4074
|
84 #if defined (HAVE_FINITE) |
|
85 return finite (x) != 0 && ! lo_ieee_is_NaN_or_NA (x); |
|
86 #elif defined (HAVE_ISINF) |
|
87 return (! isinf (x) && ! lo_ieee_is_NaN_or_NA (x)); |
|
88 #else |
|
89 return ! lo_ieee_is_NaN_or_NA (x); |
|
90 #endif |
|
91 } |
|
92 |
|
93 int |
|
94 lo_ieee_isinf (double x) |
|
95 { |
|
96 #if defined (HAVE_ISINF) |
|
97 return isinf (x); |
|
98 #elif defined (HAVE_FINITE) |
|
99 return (! (finite (x) || lo_ieee_is_NaN_or_NA (x))); |
|
100 #else |
|
101 return 0; |
|
102 #endif |
4072
|
103 } |
|
104 |
4075
|
105 int |
|
106 lo_ieee_is_NA (double x) |
|
107 { |
|
108 lo_ieee_double t; |
|
109 t.value = x; |
|
110 return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0; |
|
111 } |
|
112 |
|
113 int |
|
114 lo_ieee_is_NaN_or_NA (double x) |
|
115 { |
|
116 return lo_ieee_isnan (x); |
|
117 } |
|
118 |
4072
|
119 /* |
|
120 ;;; Local Variables: *** |
|
121 ;;; mode: C++ *** |
|
122 ;;; End: *** |
|
123 */ |