1
|
1 // mappers.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #include <float.h> |
164
|
29 #include <Complex.h> |
1
|
30 |
|
31 #include "mappers.h" |
|
32 #include "utils.h" |
|
33 |
|
34 #if defined (_AIX) && defined (__GNUG__) |
|
35 #undef finite |
|
36 #define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX) |
|
37 #endif |
|
38 |
65
|
39 #ifndef M_LOG10E |
|
40 #define M_LOG10E 0.43429448190325182765 |
|
41 #endif |
|
42 |
|
43 #ifndef M_PI |
|
44 #define M_PI 3.14159265358979323846 |
|
45 #endif |
|
46 |
1
|
47 /* |
|
48 * Double -> double mappers. |
|
49 */ |
|
50 |
|
51 double |
|
52 arg (double x) |
|
53 { |
65
|
54 if (x < 0.0) |
|
55 return M_PI; |
|
56 else |
|
57 return 0.0; |
1
|
58 } |
|
59 |
|
60 double |
|
61 conj (double x) |
|
62 { |
|
63 return x; |
|
64 } |
|
65 |
|
66 double |
|
67 fix (double x) |
|
68 { |
|
69 int tmp; |
|
70 tmp = (int) x; |
|
71 return (double) tmp; |
|
72 } |
|
73 |
|
74 double |
|
75 imag (double x) |
|
76 { |
|
77 return 0.0; |
|
78 } |
|
79 |
|
80 double |
|
81 real (double x) |
|
82 { |
|
83 return x; |
|
84 } |
|
85 |
|
86 double |
|
87 round (double x) |
|
88 { |
|
89 return D_NINT (x); |
|
90 } |
|
91 |
|
92 double |
|
93 signum (double x) |
|
94 { |
|
95 double tmp = 0.0; |
|
96 if (x < 0.0) |
|
97 tmp = -1.0; |
|
98 else if (x > 0.0) |
|
99 tmp = 1.0; |
|
100 return tmp; |
|
101 } |
|
102 |
|
103 double |
|
104 xisnan (double x) |
|
105 { |
|
106 #if defined (HAVE_ISNAN) |
|
107 return (double) isnan (x); |
|
108 #else |
|
109 return 0; |
|
110 #endif |
|
111 } |
|
112 |
|
113 double |
|
114 xfinite (double x) |
|
115 { |
|
116 #if defined (HAVE_FINITE) |
|
117 return (double) finite (x); |
|
118 #elif defined (HAVE_ISINF) && defined (HAVE_ISNAN) |
|
119 return (double) (! isinf (x) && ! isnan (x)); |
|
120 #else |
|
121 return (double) (x > -DBL_MAX && x < DBL_MAX); |
|
122 #endif |
|
123 } |
|
124 |
|
125 double |
|
126 xisinf (double x) |
|
127 { |
|
128 #if defined (HAVE_ISINF) |
|
129 return (double) isinf (x); |
|
130 #elif defined (HAVE_FINITE) && defined (HAVE_ISNAN) |
|
131 return (double) (! (finite (x) || isnan (x))); |
|
132 #else |
|
133 return (double) (x == DBL_MAX || x == -DBL_MAX); |
|
134 #endif |
|
135 } |
|
136 |
|
137 /* |
|
138 * Complex -> double mappers. |
|
139 */ |
|
140 |
|
141 double |
|
142 xisnan (const Complex& x) |
|
143 { |
|
144 #if defined (HAVE_ISNAN) |
|
145 double rx = real (x); |
|
146 double ix = imag (x); |
|
147 return (double) (isnan (rx) || isnan (ix)); |
|
148 #else |
|
149 return 0; |
|
150 #endif |
|
151 } |
|
152 |
|
153 double |
|
154 xfinite (const Complex& x) |
|
155 { |
|
156 double rx = real (x); |
|
157 double ix = imag (x); |
|
158 return (double) (! ((int) xisinf (rx) || (int) xisinf (ix))); |
|
159 } |
|
160 |
|
161 double |
|
162 xisinf (const Complex& x) |
|
163 { |
|
164 return (double) (! (int) xfinite (x)); |
|
165 } |
|
166 |
|
167 /* |
|
168 * Complex -> complex mappers. |
|
169 */ |
|
170 |
|
171 Complex |
|
172 acos (const Complex& x) |
|
173 { |
|
174 static Complex i (0, 1); |
|
175 Complex retval = -i * log (x + sqrt (x*x - 1.0)); |
|
176 return retval; |
|
177 } |
|
178 |
|
179 Complex |
|
180 acosh (const Complex& x) |
|
181 { |
|
182 Complex retval = log (x + sqrt (x*x - 1.0)); |
|
183 return retval; |
|
184 } |
|
185 |
|
186 Complex |
|
187 asin (const Complex& x) |
|
188 { |
|
189 static Complex i (0, 1); |
|
190 Complex retval = -i * log (i*x + sqrt (1.0 - x*x)); |
|
191 return retval; |
|
192 } |
|
193 |
|
194 Complex |
|
195 asinh (const Complex& x) |
|
196 { |
|
197 Complex retval = log (x + sqrt (x*x + 1.0)); |
|
198 return retval; |
|
199 } |
|
200 |
|
201 Complex |
|
202 atan (const Complex& x) |
|
203 { |
|
204 static Complex i (0, 1); |
|
205 Complex retval = i * log ((i + x) / (i - x)) / 2.0; |
|
206 return retval; |
|
207 } |
|
208 |
|
209 Complex |
|
210 atanh (const Complex& x) |
|
211 { |
|
212 static Complex i (0, 1); |
331
|
213 Complex retval = log ((1 + x) / (1 - x)) / 2.0; |
1
|
214 return retval; |
|
215 } |
|
216 |
|
217 Complex |
|
218 ceil (const Complex& x) |
|
219 { |
|
220 int re = (int) ceil (real (x)); |
|
221 int im = (int) ceil (imag (x)); |
|
222 return Complex (re, im); |
|
223 } |
|
224 |
|
225 Complex |
|
226 fix (const Complex& x) |
|
227 { |
|
228 int re = (int) real (x); |
|
229 int im = (int) imag (x); |
|
230 return Complex (re, im); |
|
231 } |
|
232 |
|
233 Complex |
|
234 floor (const Complex& x) |
|
235 { |
|
236 int re = (int) floor (real (x)); |
|
237 int im = (int) floor (imag (x)); |
|
238 return Complex (re, im); |
|
239 } |
|
240 |
|
241 Complex |
|
242 log10 (const Complex& x) |
|
243 { |
|
244 return M_LOG10E * log (x); |
|
245 } |
|
246 |
|
247 Complex |
|
248 round (const Complex& x) |
|
249 { |
|
250 double re = D_NINT (real (x)); |
|
251 double im = D_NINT (imag (x)); |
|
252 return Complex (re, im); |
|
253 } |
|
254 |
|
255 Complex |
|
256 signum (const Complex& x) |
|
257 { |
|
258 return x / abs (x); |
|
259 } |
|
260 |
|
261 Complex |
|
262 tan (const Complex& x) |
|
263 { |
|
264 Complex retval = sin (x) / cos (x); |
|
265 return retval; |
|
266 } |
|
267 |
|
268 Complex |
|
269 tanh (const Complex& x) |
|
270 { |
|
271 Complex retval = sinh (x) / cosh (x); |
|
272 return retval; |
|
273 } |
|
274 |
|
275 /* |
|
276 ;;; Local Variables: *** |
|
277 ;;; mode: C++ *** |
|
278 ;;; page-delimiter: "^/\\*" *** |
|
279 ;;; End: *** |
|
280 */ |