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 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <float.h> |
|
29 |
|
30 #include "mappers.h" |
|
31 #include "utils.h" |
|
32 |
|
33 #if defined (_AIX) && defined (__GNUG__) |
|
34 #undef finite |
|
35 #define finite(x) ((x) < DBL_MAX && (x) > -DBL_MAX) |
|
36 #endif |
|
37 |
65
|
38 #ifndef M_LOG10E |
|
39 #define M_LOG10E 0.43429448190325182765 |
|
40 #endif |
|
41 |
|
42 #ifndef M_PI |
|
43 #define M_PI 3.14159265358979323846 |
|
44 #endif |
|
45 |
1
|
46 /* |
|
47 * Double -> double mappers. |
|
48 */ |
|
49 |
|
50 double |
|
51 arg (double x) |
|
52 { |
65
|
53 if (x < 0.0) |
|
54 return M_PI; |
|
55 else |
|
56 return 0.0; |
1
|
57 } |
|
58 |
|
59 double |
|
60 conj (double x) |
|
61 { |
|
62 return x; |
|
63 } |
|
64 |
|
65 double |
|
66 fix (double x) |
|
67 { |
|
68 int tmp; |
|
69 tmp = (int) x; |
|
70 return (double) tmp; |
|
71 } |
|
72 |
|
73 double |
|
74 imag (double x) |
|
75 { |
|
76 return 0.0; |
|
77 } |
|
78 |
|
79 double |
|
80 real (double x) |
|
81 { |
|
82 return x; |
|
83 } |
|
84 |
|
85 double |
|
86 round (double x) |
|
87 { |
|
88 return D_NINT (x); |
|
89 } |
|
90 |
|
91 double |
|
92 signum (double x) |
|
93 { |
|
94 double tmp = 0.0; |
|
95 if (x < 0.0) |
|
96 tmp = -1.0; |
|
97 else if (x > 0.0) |
|
98 tmp = 1.0; |
|
99 return tmp; |
|
100 } |
|
101 |
|
102 double |
|
103 xisnan (double x) |
|
104 { |
|
105 #if defined (HAVE_ISNAN) |
|
106 return (double) isnan (x); |
|
107 #else |
|
108 return 0; |
|
109 #endif |
|
110 } |
|
111 |
|
112 double |
|
113 xfinite (double x) |
|
114 { |
|
115 #if defined (HAVE_FINITE) |
|
116 return (double) finite (x); |
|
117 #elif defined (HAVE_ISINF) && defined (HAVE_ISNAN) |
|
118 return (double) (! isinf (x) && ! isnan (x)); |
|
119 #else |
|
120 return (double) (x > -DBL_MAX && x < DBL_MAX); |
|
121 #endif |
|
122 } |
|
123 |
|
124 double |
|
125 xisinf (double x) |
|
126 { |
|
127 #if defined (HAVE_ISINF) |
|
128 return (double) isinf (x); |
|
129 #elif defined (HAVE_FINITE) && defined (HAVE_ISNAN) |
|
130 return (double) (! (finite (x) || isnan (x))); |
|
131 #else |
|
132 return (double) (x == DBL_MAX || x == -DBL_MAX); |
|
133 #endif |
|
134 } |
|
135 |
|
136 /* |
|
137 * Complex -> double mappers. |
|
138 */ |
|
139 |
|
140 double |
|
141 xisnan (const Complex& x) |
|
142 { |
|
143 #if defined (HAVE_ISNAN) |
|
144 double rx = real (x); |
|
145 double ix = imag (x); |
|
146 return (double) (isnan (rx) || isnan (ix)); |
|
147 #else |
|
148 return 0; |
|
149 #endif |
|
150 } |
|
151 |
|
152 double |
|
153 xfinite (const Complex& x) |
|
154 { |
|
155 double rx = real (x); |
|
156 double ix = imag (x); |
|
157 return (double) (! ((int) xisinf (rx) || (int) xisinf (ix))); |
|
158 } |
|
159 |
|
160 double |
|
161 xisinf (const Complex& x) |
|
162 { |
|
163 return (double) (! (int) xfinite (x)); |
|
164 } |
|
165 |
|
166 /* |
|
167 * Complex -> complex mappers. |
|
168 */ |
|
169 |
|
170 Complex |
|
171 acos (const Complex& x) |
|
172 { |
|
173 static Complex i (0, 1); |
|
174 Complex retval = -i * log (x + sqrt (x*x - 1.0)); |
|
175 return retval; |
|
176 } |
|
177 |
|
178 Complex |
|
179 acosh (const Complex& x) |
|
180 { |
|
181 Complex retval = log (x + sqrt (x*x - 1.0)); |
|
182 return retval; |
|
183 } |
|
184 |
|
185 Complex |
|
186 asin (const Complex& x) |
|
187 { |
|
188 static Complex i (0, 1); |
|
189 Complex retval = -i * log (i*x + sqrt (1.0 - x*x)); |
|
190 return retval; |
|
191 } |
|
192 |
|
193 Complex |
|
194 asinh (const Complex& x) |
|
195 { |
|
196 Complex retval = log (x + sqrt (x*x + 1.0)); |
|
197 return retval; |
|
198 } |
|
199 |
|
200 Complex |
|
201 atan (const Complex& x) |
|
202 { |
|
203 static Complex i (0, 1); |
|
204 Complex retval = i * log ((i + x) / (i - x)) / 2.0; |
|
205 return retval; |
|
206 } |
|
207 |
|
208 Complex |
|
209 atanh (const Complex& x) |
|
210 { |
|
211 static Complex i (0, 1); |
|
212 Complex retval = log ((i + x) / (i - x)) / 2.0; |
|
213 return retval; |
|
214 } |
|
215 |
|
216 Complex |
|
217 ceil (const Complex& x) |
|
218 { |
|
219 int re = (int) ceil (real (x)); |
|
220 int im = (int) ceil (imag (x)); |
|
221 return Complex (re, im); |
|
222 } |
|
223 |
|
224 Complex |
|
225 fix (const Complex& x) |
|
226 { |
|
227 int re = (int) real (x); |
|
228 int im = (int) imag (x); |
|
229 return Complex (re, im); |
|
230 } |
|
231 |
|
232 Complex |
|
233 floor (const Complex& x) |
|
234 { |
|
235 int re = (int) floor (real (x)); |
|
236 int im = (int) floor (imag (x)); |
|
237 return Complex (re, im); |
|
238 } |
|
239 |
|
240 Complex |
|
241 log10 (const Complex& x) |
|
242 { |
|
243 return M_LOG10E * log (x); |
|
244 } |
|
245 |
|
246 Complex |
|
247 round (const Complex& x) |
|
248 { |
|
249 double re = D_NINT (real (x)); |
|
250 double im = D_NINT (imag (x)); |
|
251 return Complex (re, im); |
|
252 } |
|
253 |
|
254 Complex |
|
255 signum (const Complex& x) |
|
256 { |
|
257 return x / abs (x); |
|
258 } |
|
259 |
|
260 Complex |
|
261 tan (const Complex& x) |
|
262 { |
|
263 Complex retval = sin (x) / cos (x); |
|
264 return retval; |
|
265 } |
|
266 |
|
267 Complex |
|
268 tanh (const Complex& x) |
|
269 { |
|
270 Complex retval = sinh (x) / cosh (x); |
|
271 return retval; |
|
272 } |
|
273 |
|
274 /* |
|
275 ;;; Local Variables: *** |
|
276 ;;; mode: C++ *** |
|
277 ;;; page-delimiter: "^/\\*" *** |
|
278 ;;; End: *** |
|
279 */ |