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