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> |
3121
|
28 #include <cmath> |
1967
|
29 |
|
30 #include "lo-error.h" |
|
31 #include "lo-ieee.h" |
|
32 #include "lo-mappers.h" |
3121
|
33 #include "lo-specfun.h" |
1967
|
34 #include "lo-utils.h" |
|
35 #include "oct-cmplx.h" |
|
36 |
|
37 #include "f77-fcn.h" |
|
38 |
|
39 #if defined (_AIX) && defined (__GNUG__) |
|
40 #undef finite |
|
41 #define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX) |
|
42 #endif |
|
43 |
|
44 extern "C" |
|
45 { |
3049
|
46 int F77_FCN (xdgamma, XDGAMMA) (const double&, double&); |
1967
|
47 |
|
48 int F77_FCN (dlgams, DLGAMS) (const double&, double&, double&); |
|
49 } |
|
50 |
|
51 #ifndef M_LOG10E |
|
52 #define M_LOG10E 0.43429448190325182765 |
|
53 #endif |
|
54 |
|
55 #ifndef M_PI |
|
56 #define M_PI 3.14159265358979323846 |
|
57 #endif |
|
58 |
|
59 #if defined (HAVE_LGAMMA) && ! defined (SIGNGAM_DECLARED) |
|
60 extern int signgam; |
|
61 #endif |
|
62 |
|
63 // Double -> double mappers. |
|
64 |
|
65 double |
|
66 arg (double x) |
|
67 { |
|
68 if (x < 0.0) |
|
69 return M_PI; |
|
70 else |
|
71 #if defined (HAVE_ISNAN) |
|
72 return xisnan (x) ? octave_NaN : 0.0; |
|
73 #else |
|
74 return 0.0; |
|
75 #endif |
|
76 } |
|
77 |
|
78 double |
|
79 conj (double x) |
|
80 { |
|
81 return x; |
|
82 } |
|
83 |
|
84 double |
|
85 fix (double x) |
|
86 { |
3012
|
87 return x > 0 ? floor (x) : ceil (x); |
1967
|
88 } |
|
89 |
|
90 double |
|
91 imag (double x) |
|
92 { |
|
93 #if defined (HAVE_ISNAN) |
|
94 return xisnan (x) ? octave_NaN : 0.0; |
|
95 #else |
|
96 return 0.0; |
|
97 #endif |
|
98 } |
|
99 |
|
100 double |
|
101 real (double x) |
|
102 { |
|
103 return x; |
|
104 } |
|
105 |
|
106 double |
|
107 round (double x) |
|
108 { |
|
109 return D_NINT (x); |
|
110 } |
|
111 |
|
112 double |
|
113 signum (double x) |
|
114 { |
|
115 double tmp = 0.0; |
|
116 if (x < 0.0) |
|
117 tmp = -1.0; |
|
118 else if (x > 0.0) |
|
119 tmp = 1.0; |
|
120 |
|
121 #if defined (HAVE_ISNAN) |
|
122 return xisnan (x) ? octave_NaN : tmp; |
|
123 #else |
|
124 return tmp; |
|
125 #endif |
|
126 } |
|
127 |
|
128 double |
|
129 xerf (double x) |
|
130 { |
|
131 #if defined (HAVE_ERF) |
|
132 return erf (x); |
|
133 #else |
|
134 (*current_liboctave_error_handler) |
|
135 ("erf (x) not available on this system"); |
|
136 #endif |
|
137 } |
|
138 |
|
139 double |
|
140 xerfc (double x) |
|
141 { |
|
142 #if defined (HAVE_ERFC) |
|
143 return erfc (x); |
|
144 #else |
|
145 (*current_liboctave_error_handler) |
|
146 ("erfc (x) not available on this system"); |
|
147 #endif |
|
148 } |
|
149 |
|
150 double |
|
151 xisnan (double x) |
|
152 { |
|
153 #if defined (HAVE_ISNAN) |
3069
|
154 return isnan (x) != 0; |
1967
|
155 #else |
|
156 return 0; |
|
157 #endif |
|
158 } |
|
159 |
|
160 double |
|
161 xfinite (double x) |
|
162 { |
|
163 #if defined (HAVE_FINITE) |
3069
|
164 return finite (x) != 0; |
1967
|
165 #elif defined (HAVE_ISINF) && defined (HAVE_ISNAN) |
2800
|
166 return (! isinf (x) && ! isnan (x)); |
1967
|
167 #else |
|
168 return 1; |
|
169 #endif |
|
170 } |
|
171 |
|
172 double |
|
173 xgamma (double x) |
|
174 { |
3049
|
175 double result; |
|
176 |
|
177 F77_XFCN (xdgamma, XDGAMMA, (x, result)); |
|
178 |
|
179 return result; |
1967
|
180 } |
|
181 |
|
182 double |
|
183 xisinf (double x) |
|
184 { |
|
185 #if defined (HAVE_ISINF) |
2800
|
186 return isinf (x); |
1967
|
187 #elif defined (HAVE_FINITE) && defined (HAVE_ISNAN) |
2800
|
188 return (! (finite (x) || isnan (x))); |
1967
|
189 #else |
|
190 return 0; |
|
191 #endif |
|
192 } |
|
193 |
|
194 double |
|
195 xlgamma (double x) |
|
196 { |
|
197 double result; |
|
198 double sgngam; |
|
199 |
3049
|
200 F77_XFCN (dlgams, DLGAMS, (x, result, sgngam)); |
1967
|
201 |
|
202 return result; |
|
203 } |
|
204 |
|
205 // Complex -> double mappers. |
|
206 |
|
207 double |
|
208 xisnan (const Complex& x) |
|
209 { |
|
210 #if defined (HAVE_ISNAN) |
2800
|
211 return (isnan (real (x)) || isnan (imag (x))); |
1967
|
212 #else |
|
213 return 0; |
|
214 #endif |
|
215 } |
|
216 |
|
217 double |
|
218 xfinite (const Complex& x) |
|
219 { |
2800
|
220 return (! (xisinf (real (x)) || xisinf (imag (x)))); |
1967
|
221 } |
|
222 |
|
223 double |
|
224 xisinf (const Complex& x) |
|
225 { |
2800
|
226 return (! xfinite (x)); |
1967
|
227 } |
|
228 |
|
229 // Complex -> complex mappers. |
|
230 |
|
231 Complex |
|
232 acos (const Complex& x) |
|
233 { |
|
234 static Complex i (0, 1); |
3056
|
235 |
|
236 return (real (x) * imag (x) < 0.0) ? i * acosh (x) : -i * acosh (x); |
1967
|
237 } |
|
238 |
|
239 Complex |
|
240 acosh (const Complex& x) |
|
241 { |
3056
|
242 return log (x + sqrt (x*x - 1.0)); |
1967
|
243 } |
|
244 |
|
245 Complex |
|
246 asin (const Complex& x) |
|
247 { |
|
248 static Complex i (0, 1); |
3056
|
249 |
|
250 return -i * log (i*x + sqrt (1.0 - x*x)); |
1967
|
251 } |
|
252 |
|
253 Complex |
|
254 asinh (const Complex& x) |
|
255 { |
3056
|
256 return log (x + sqrt (x*x + 1.0)); |
1967
|
257 } |
|
258 |
|
259 Complex |
|
260 atan (const Complex& x) |
|
261 { |
|
262 static Complex i (0, 1); |
3056
|
263 |
|
264 return i * log ((i + x) / (i - x)) / 2.0; |
1967
|
265 } |
|
266 |
|
267 Complex |
|
268 atanh (const Complex& x) |
|
269 { |
3092
|
270 return log ((1.0 + x) / (1.0 - x)) / 2.0; |
1967
|
271 } |
|
272 |
|
273 Complex |
|
274 ceil (const Complex& x) |
|
275 { |
2800
|
276 return Complex (ceil (real (x)), ceil (imag (x))); |
1967
|
277 } |
|
278 |
|
279 Complex |
|
280 fix (const Complex& x) |
|
281 { |
3012
|
282 return Complex (fix (real (x)), fix (imag (x))); |
1967
|
283 } |
|
284 |
|
285 Complex |
|
286 floor (const Complex& x) |
|
287 { |
2800
|
288 return Complex (floor (real (x)), floor (imag (x))); |
1967
|
289 } |
|
290 |
|
291 Complex |
|
292 log10 (const Complex& x) |
|
293 { |
|
294 return M_LOG10E * log (x); |
|
295 } |
|
296 |
|
297 Complex |
|
298 round (const Complex& x) |
|
299 { |
2800
|
300 return Complex (D_NINT (real (x)), D_NINT (imag (x))); |
1967
|
301 } |
|
302 |
|
303 Complex |
|
304 signum (const Complex& x) |
|
305 { |
|
306 return x / abs (x); |
|
307 } |
|
308 |
|
309 Complex |
|
310 tan (const Complex& x) |
|
311 { |
3056
|
312 return sin (x) / cos (x); |
1967
|
313 } |
|
314 |
|
315 Complex |
|
316 tanh (const Complex& x) |
|
317 { |
3056
|
318 return sinh (x) / cosh (x); |
1967
|
319 } |
|
320 |
|
321 /* |
|
322 ;;; Local Variables: *** |
|
323 ;;; mode: C++ *** |
|
324 ;;; End: *** |
|
325 */ |