GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
util
lo-cieee.c
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2002-2013 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 3 of the License, or (at your
10
option) any 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, see
19
<http://www.gnu.org/licenses/>.
20
21
*/
22
23
#ifdef HAVE_CONFIG_H
24
#include <config.h>
25
#endif
26
27
#include <float.h>
28
29
#if defined (HAVE_FLOATINGPOINT_H)
30
#include <floatingpoint.h>
31
#endif
32
33
#if defined (HAVE_IEEEFP_H)
34
#include <ieeefp.h>
35
#endif
36
37
#include "
lo-ieee.h
"
38
#include "
lo-math.h
"
39
40
#if ! defined (HAVE_ISNAN) && defined (HAVE__ISNAN)
41
#define isnan _isnan
42
#define HAVE_ISNAN 1
43
#endif
44
45
#if ! defined (HAVE_FINITE) && defined (HAVE__FINITE)
46
#define finite _finite
47
#define HAVE_FINITE 1
48
#endif
49
50
#if defined (_AIX) && defined (__GNUG__)
51
#undef finite
52
#define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX)
53
#endif
54
55
/* Octave's idea of infinity. */
56
double
octave_Inf
;
57
float
octave_Float_Inf
;
58
59
/* Octave's idea of a missing value. */
60
double
octave_NA
;
61
float
octave_Float_NA
;
62
63
/* Octave's idea of not a number. */
64
double
octave_NaN
;
65
float
octave_Float_NaN
;
66
67
int
lo_ieee_hw
;
68
int
lo_ieee_lw
;
69
70
int
71
__lo_ieee_isnan
(
double
x
)
72
{
73
#if defined (HAVE_ISNAN)
74
return
isnan (x);
75
#else
76
return
0;
77
#endif
78
}
79
80
int
81
__lo_ieee_finite
(
double
x
)
82
{
83
#if defined (HAVE_FINITE)
84
return
finite (x) != 0 && !
__lo_ieee_isnan
(x);
85
#elif defined (HAVE_ISINF)
86
return
(! isinf (x) && !
__lo_ieee_isnan
(x));
87
#else
88
return
!
__lo_ieee_isnan
(x);
89
#endif
90
}
91
92
int
93
__lo_ieee_isinf
(
double
x
)
94
{
95
#if defined (HAVE_ISINF)
96
return
isinf (x);
97
#elif defined (HAVE_FINITE)
98
return
(! (finite (x) ||
__lo_ieee_isnan
(x)));
99
#else
100
return
0;
101
#endif
102
}
103
104
int
105
__lo_ieee_is_NA
(
double
x
)
106
{
107
#if defined (HAVE_ISNAN)
108
lo_ieee_double
t;
109
t.
value
=
x
;
110
return
(isnan (x) && t.
word
[lo_ieee_hw] ==
LO_IEEE_NA_HW
111
&& t.
word
[lo_ieee_lw] ==
LO_IEEE_NA_LW
) ? 1 : 0;
112
#else
113
return
0;
114
#endif
115
}
116
117
int
118
__lo_ieee_is_old_NA
(
double
x
)
119
{
120
#if defined (HAVE_ISNAN)
121
lo_ieee_double
t;
122
t.
value
=
x
;
123
return
(isnan (x) && t.
word
[lo_ieee_lw] ==
LO_IEEE_NA_LW_OLD
124
&& t.
word
[lo_ieee_hw] ==
LO_IEEE_NA_HW_OLD
) ? 1 : 0;
125
#else
126
return
0;
127
#endif
128
}
129
130
double
131
__lo_ieee_replace_old_NA
(
double
x
)
132
{
133
if
(
__lo_ieee_is_old_NA
(x))
134
return
lo_ieee_na_value
();
135
else
136
return
x
;
137
}
138
139
int
140
__lo_ieee_is_NaN_or_NA
(
double
x
)
141
{
142
return
__lo_ieee_isnan
(x);
143
}
144
145
double
146
lo_ieee_inf_value
(
void
)
147
{
148
return
octave_Inf
;
149
}
150
151
double
152
lo_ieee_na_value
(
void
)
153
{
154
return
octave_NA
;
155
}
156
157
double
158
lo_ieee_nan_value
(
void
)
159
{
160
return
octave_NaN
;
161
}
162
163
#if ! (defined (signbit) || defined (HAVE_DECL_SIGNBIT)) && defined (HAVE_SIGNBIT)
164
extern
int
signbit (
double
);
165
#endif
166
167
int
168
__lo_ieee_signbit
(
double
x
)
169
{
170
/* In the following definitions, only check x < 0 explicitly to avoid
171
a function call when it looks like signbit or copysign are actually
172
functions. */
173
174
#if defined (signbit)
175
return
signbit (x);
176
#elif defined (HAVE_SIGNBIT)
177
return
(x < 0 || signbit (x));
178
#elif defined (copysign)
179
return
(copysign (1.0, x) < 0);
180
#elif defined (HAVE_COPYSIGN)
181
return
(x < 0 || copysign (1.0, x) < 0);
182
#else
183
return
x < 0;
184
#endif
185
}
186
187
int
188
__lo_ieee_float_isnan
(
float
x
)
189
{
190
#if defined (HAVE_ISNAN)
191
return
isnan (x);
192
#else
193
return
0;
194
#endif
195
}
196
197
int
198
__lo_ieee_float_finite
(
float
x
)
199
{
200
#if defined (HAVE_FINITE)
201
return
finite (x) != 0 && !
__lo_ieee_float_isnan
(x);
202
#elif defined (HAVE_ISINF)
203
return
(! isinf (x) && !
__lo_ieee_float_isnan
(x));
204
#else
205
return
!
__lo_ieee_float_isnan
(x);
206
#endif
207
}
208
209
int
210
__lo_ieee_float_isinf
(
float
x
)
211
{
212
#if defined (HAVE_ISINF)
213
return
isinf (x);
214
#elif defined (HAVE_FINITE)
215
return
(! (finite (x) ||
__lo_ieee_float_isnan
(x)));
216
#else
217
return
0;
218
#endif
219
}
220
221
int
222
__lo_ieee_float_is_NA
(
float
x
)
223
{
224
#if defined (HAVE_ISNAN)
225
lo_ieee_float
t;
226
t.
value
=
x
;
227
return
(isnan (x) && (t.
word
==
LO_IEEE_NA_FLOAT
)) ? 1 : 0;
228
#else
229
return
0;
230
#endif
231
}
232
233
int
234
__lo_ieee_float_is_NaN_or_NA
(
float
x
)
235
{
236
return
__lo_ieee_float_isnan
(x);
237
}
238
239
float
240
lo_ieee_float_inf_value
(
void
)
241
{
242
return
octave_Float_Inf
;
243
}
244
245
float
246
lo_ieee_float_na_value
(
void
)
247
{
248
return
octave_Float_NA
;
249
}
250
251
float
252
lo_ieee_float_nan_value
(
void
)
253
{
254
return
octave_Float_NaN
;
255
}
256
257
#if ! (defined (signbit) || defined (HAVE_DECL_SIGNBIT)) && defined (HAVE_SIGNBIT)
258
extern
int
signbit (
float
);
259
#endif
260
261
int
262
__lo_ieee_float_signbit
(
float
x
)
263
{
264
/* In the following definitions, only check x < 0 explicitly to avoid
265
a function call when it looks like signbit or copysign are actually
266
functions. */
267
268
#if defined (signbit)
269
return
signbit (x);
270
#elif defined (HAVE_SIGNBIT)
271
return
(x < 0 || signbit (x));
272
#elif defined (copysign)
273
return
(copysign (1.0, x) < 0);
274
#elif defined (HAVE_COPYSIGN)
275
return
(x < 0 || copysign (1.0, x) < 0);
276
#else
277
return
x < 0;
278
#endif
279
}
Generated on Mon Dec 30 2013 03:04:54 for GNU Octave by
1.8.1.2