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