Mercurial > hg > octave-nkf
annotate liboctave/numeric/lo-mappers.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 3fa35defe495 |
children |
rev | line source |
---|---|
1967 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19572
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10459
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
1967 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1967 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1967 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cfloat> | |
3268 | 29 |
1967 | 30 #include "lo-error.h" |
31 #include "lo-ieee.h" | |
32 #include "lo-mappers.h" | |
7231 | 33 #include "lo-math.h" |
3121 | 34 #include "lo-specfun.h" |
1967 | 35 #include "lo-utils.h" |
36 #include "oct-cmplx.h" | |
37 | |
38 #include "f77-fcn.h" | |
39 | |
3248 | 40 // double -> double mappers. |
1967 | 41 |
11237
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
42 // Both xtrunc and xround belong here so we can keep gnulib:: out of |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
43 // lo-mappers.h. |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
44 |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
45 double |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
46 xtrunc (double x) |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
47 { |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
48 return gnulib::trunc (x); |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
49 } |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
50 |
13737
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
51 double |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
52 xcopysign (double x, double y) |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
53 { |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
54 return gnulib::copysign (x, y); |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
55 } |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
56 |
11525
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 double xfloor (double x) |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
58 { |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 return gnulib::floor (x); |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 } |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
61 |
11237
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
62 double |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
63 xround (double x) |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
64 { |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
65 return gnulib::round (x); |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
66 } |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
67 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
68 double |
7636
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
69 xroundb (double x) |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
70 { |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
71 double t = xround (x); |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
72 |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
73 if (fabs (x - t) == 0.5) |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
74 t = 2 * xtrunc (0.5 * t); |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
75 |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
76 return t; |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
77 } |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
78 |
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7231
diff
changeset
|
79 double |
1967 | 80 signum (double x) |
81 { | |
82 double tmp = 0.0; | |
4984 | 83 |
1967 | 84 if (x < 0.0) |
85 tmp = -1.0; | |
86 else if (x > 0.0) | |
87 tmp = 1.0; | |
88 | |
89 return xisnan (x) ? octave_NaN : tmp; | |
90 } | |
91 | |
5904 | 92 double |
93 xlog2 (double x) | |
94 { | |
19037
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17843
diff
changeset
|
95 return gnulib::log2 (x); |
5904 | 96 } |
97 | |
7740 | 98 Complex |
99 xlog2 (const Complex& x) | |
100 { | |
101 #if defined (M_LN2) | |
102 static double ln2 = M_LN2; | |
103 #else | |
19118
161ebb78ac1b
use gnulib::log and gnulib::logf functions
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
104 static double ln2 = gnulib::log (2); |
7740 | 105 #endif |
106 | |
107 return std::log (x) / ln2; | |
108 } | |
109 | |
5904 | 110 double |
111 xexp2 (double x) | |
112 { | |
113 #if defined (HAVE_EXP2) | |
114 return exp2 (x); | |
115 #else | |
116 #if defined (M_LN2) | |
117 static double ln2 = M_LN2; | |
118 #else | |
19118
161ebb78ac1b
use gnulib::log and gnulib::logf functions
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
119 static double ln2 = gnulib::log (2); |
5904 | 120 #endif |
121 | |
122 return exp (x * ln2); | |
123 #endif | |
124 } | |
125 | |
7740 | 126 double |
127 xlog2 (double x, int& exp) | |
128 { | |
17843 | 129 return gnulib::frexp (x, &exp); |
7740 | 130 } |
131 | |
132 Complex | |
133 xlog2 (const Complex& x, int& exp) | |
134 { | |
135 double ax = std::abs (x); | |
136 double lax = xlog2 (ax, exp); | |
9319
0d9178575dd7
fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
137 return (ax != lax) ? (x / ax) * lax : x; |
7740 | 138 } |
139 | |
3248 | 140 // double -> bool mappers. |
141 | |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
142 #if ! defined(HAVE_CMATH_ISNAN) |
3248 | 143 bool |
1967 | 144 xisnan (double x) |
145 { | |
4074 | 146 return lo_ieee_isnan (x); |
1967 | 147 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
148 #endif |
1967 | 149 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
150 #if ! defined(HAVE_CMATH_ISFINITE) |
3248 | 151 bool |
1967 | 152 xfinite (double x) |
153 { | |
4074 | 154 return lo_ieee_finite (x); |
1967 | 155 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
156 #endif |
1967 | 157 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
158 #if ! defined(HAVE_CMATH_ISINF) |
3248 | 159 bool |
1967 | 160 xisinf (double x) |
161 { | |
4074 | 162 return lo_ieee_isinf (x); |
1967 | 163 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
164 #endif |
1967 | 165 |
4025 | 166 bool |
167 octave_is_NA (double x) | |
168 { | |
169 return lo_ieee_is_NA (x); | |
170 } | |
171 | |
3248 | 172 // (double, double) -> double mappers. |
1967 | 173 |
3248 | 174 // complex -> complex mappers. |
1967 | 175 |
176 Complex | |
177 acos (const Complex& x) | |
178 { | |
179 static Complex i (0, 1); | |
3056 | 180 |
19434
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
181 Complex tmp; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
182 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
183 if (imag (x) == 0.0) |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
184 { |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
185 // If the imaginary part of X is 0, then avoid generating an |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
186 // imaginary part of -0 for the expression 1-x*x. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
187 // This effectively chooses the same phase of the branch cut as Matlab. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
188 double xr = real (x); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
189 tmp = Complex (1.0 - xr*xr); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
190 } |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
191 else |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
192 tmp = 1.0 - x*x; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
193 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
194 return -i * log (x + i * sqrt (tmp)); |
1967 | 195 } |
196 | |
197 Complex | |
198 acosh (const Complex& x) | |
199 { | |
19935
554aaaf99644
Fix return phase of acosh to match Matlab (bug #44286).
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
200 return log (x + sqrt (x + 1.0) * sqrt (x - 1.0)); |
1967 | 201 } |
202 | |
203 Complex | |
204 asin (const Complex& x) | |
205 { | |
206 static Complex i (0, 1); | |
3056 | 207 |
19434
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
208 Complex tmp; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
209 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
210 if (imag (x) == 0.0) |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
211 { |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
212 // If the imaginary part of X is 0, then avoid generating an |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
213 // imaginary part of -0 for the expression 1-x*x. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
214 // This effectively chooses the same phase of the branch cut as Matlab. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
215 double xr = real (x); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
216 tmp = Complex (1.0 - xr*xr); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
217 } |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
218 else |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
219 tmp = 1.0 - x*x; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
220 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
221 return -i * log (i*x + sqrt (tmp)); |
1967 | 222 } |
223 | |
224 Complex | |
225 asinh (const Complex& x) | |
226 { | |
3056 | 227 return log (x + sqrt (x*x + 1.0)); |
1967 | 228 } |
229 | |
230 Complex | |
231 atan (const Complex& x) | |
232 { | |
233 static Complex i (0, 1); | |
3056 | 234 |
235 return i * log ((i + x) / (i - x)) / 2.0; | |
1967 | 236 } |
237 | |
238 Complex | |
239 atanh (const Complex& x) | |
240 { | |
3092 | 241 return log ((1.0 + x) / (1.0 - x)) / 2.0; |
1967 | 242 } |
243 | |
3248 | 244 // complex -> bool mappers. |
245 | |
246 bool | |
4025 | 247 octave_is_NA (const Complex& x) |
248 { | |
249 return (octave_is_NA (real (x)) || octave_is_NA (imag (x))); | |
250 } | |
251 | |
252 bool | |
253 octave_is_NaN_or_NA (const Complex& x) | |
254 { | |
5389 | 255 return (xisnan (real (x)) || xisnan (imag (x))); |
4025 | 256 } |
257 | |
3248 | 258 // (complex, complex) -> complex mappers. |
259 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
260 // FIXME: need to handle NA too? |
4025 | 261 |
3248 | 262 Complex |
263 xmin (const Complex& x, const Complex& y) | |
264 { | |
3757 | 265 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y); |
3248 | 266 } |
267 | |
268 Complex | |
269 xmax (const Complex& x, const Complex& y) | |
270 { | |
3757 | 271 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y); |
3248 | 272 } |
273 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
274 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
275 // float -> float mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
276 |
11237
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
277 // Both xtrunc and xround belong here so we can keep gnulib:: out of |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
278 // lo-mappers.h. |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
279 |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
280 float |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
281 xtrunc (float x) |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
282 { |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
283 return gnulib::truncf (x); |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
284 } |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
285 |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
286 float |
13737
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
287 xcopysign (float x, float y) |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
288 { |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
289 return gnulib::copysignf (x, y); |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
290 } |
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
291 |
15409
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
292 float xfloor (float x) |
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
293 { |
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
294 return gnulib::floorf (x); |
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
295 } |
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
296 |
13737
30414ff19d5e
Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
297 float |
11237
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
298 xround (float x) |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
299 { |
15409
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
300 return gnulib::roundf (x); |
11237
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
301 } |
110e570e5f8d
keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents:
11212
diff
changeset
|
302 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
303 float |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
304 xroundb (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
305 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
306 float t = xround (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
307 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
308 if (fabsf (x - t) == 0.5) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
309 t = 2 * xtrunc (0.5 * t); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
310 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
311 return t; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
312 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
313 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
314 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
315 signum (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
316 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
317 float tmp = 0.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
318 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
319 if (x < 0.0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
320 tmp = -1.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
321 else if (x > 0.0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
322 tmp = 1.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
323 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
324 return xisnan (x) ? octave_Float_NaN : tmp; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
325 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
326 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
327 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
328 xlog2 (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
329 { |
19037
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17843
diff
changeset
|
330 return gnulib::log2f (x); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
331 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
332 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
333 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
334 xlog2 (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
335 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
336 #if defined (M_LN2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
337 static float ln2 = M_LN2; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
338 #else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
339 static float ln2 = log (2); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
340 #endif |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
341 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
342 return std::log (x) / ln2; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
343 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
344 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
345 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
346 xexp2 (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
347 { |
15452
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15409
diff
changeset
|
348 #if defined (HAVE_EXP2F) |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15409
diff
changeset
|
349 return exp2f (x); |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15409
diff
changeset
|
350 #elif defined (HAVE_EXP2) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
351 return exp2 (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
352 #else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
353 #if defined (M_LN2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
354 static float ln2 = M_LN2; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
355 #else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
356 static float ln2 = log2 (2); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
357 #endif |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
358 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
359 return exp (x * ln2); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
360 #endif |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
361 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
362 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
363 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
364 xlog2 (float x, int& exp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
365 { |
17843 | 366 return gnulib::frexpf (x, &exp); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
367 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
368 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
369 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
370 xlog2 (const FloatComplex& x, int& exp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
371 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
372 float ax = std::abs (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
373 float lax = xlog2 (ax, exp); |
9319
0d9178575dd7
fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
374 return (ax != lax) ? (x / ax) * lax : x; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
375 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
376 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
377 // float -> bool mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
378 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
379 #if ! defined(HAVE_CMATH_ISNANF) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
380 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
381 xisnan (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
382 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
383 return lo_ieee_isnan (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
384 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
385 #endif |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
386 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
387 #if ! defined(HAVE_CMATH_ISFINITEF) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
388 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
389 xfinite (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
390 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
391 return lo_ieee_finite (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
392 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
393 #endif |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
394 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
395 #if ! defined(HAVE_CMATH_ISINFF) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
396 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
397 xisinf (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
398 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
399 return lo_ieee_isinf (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
400 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
401 #endif |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
402 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
403 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
404 octave_is_NA (float x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
405 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
406 return lo_ieee_is_NA (x); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
407 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
408 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
409 // (float, float) -> float mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
410 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
411 // complex -> complex mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
412 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
413 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
414 acos (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
415 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
416 static FloatComplex i (0, 1); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
417 |
19434
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
418 FloatComplex tmp; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
419 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
420 if (imag (x) == 0.0f) |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
421 { |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
422 // If the imaginary part of X is 0, then avoid generating an |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
423 // imaginary part of -0 for the expression 1-x*x. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
424 // This effectively chooses the same phase of the branch cut as Matlab. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
425 float xr = real (x); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
426 tmp = FloatComplex (1.0f - xr*xr); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
427 } |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
428 else |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
429 tmp = 1.0f - x*x; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
430 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
431 return -i * log (x + i * sqrt (tmp)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
432 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
433 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
434 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
435 acosh (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
436 { |
19935
554aaaf99644
Fix return phase of acosh to match Matlab (bug #44286).
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
437 return log (x + sqrt (x + 1.0f) * sqrt (x - 1.0f)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
438 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
439 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
440 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
441 asin (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
442 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
443 static FloatComplex i (0, 1); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
444 |
19434
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
445 FloatComplex tmp; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
446 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
447 if (imag (x) == 0.0f) |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
448 { |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
449 // If the imaginary part of X is 0, then avoid generating an |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
450 // imaginary part of -0 for the expression 1-x*x. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
451 // This effectively chooses the same phase of the branch cut as Matlab. |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
452 float xr = real (x); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
453 tmp = FloatComplex (1.0f - xr*xr); |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
454 } |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
455 else |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
456 tmp = 1.0f - x*x; |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
457 |
ba7e42dea4b2
Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
458 return -i * log (i*x + sqrt (tmp)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
459 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
460 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
461 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
462 asinh (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
463 { |
19943
9155bab86647
use 0.0f style constants instead of static_cast<float> (0.0)
John W. Eaton <jwe@octave.org>
parents:
19935
diff
changeset
|
464 return log (x + sqrt (x*x + 1.0f)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
465 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
466 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
467 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
468 atan (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
469 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
470 static FloatComplex i (0, 1); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
471 |
19943
9155bab86647
use 0.0f style constants instead of static_cast<float> (0.0)
John W. Eaton <jwe@octave.org>
parents:
19935
diff
changeset
|
472 return i * log ((i + x) / (i - x)) / 2.0f; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
473 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
474 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
475 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
476 atanh (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
477 { |
19944
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19943
diff
changeset
|
478 return log ((1.0f + x) / (1.0f - x)) / 2.0f; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
479 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
480 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
481 // complex -> bool mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
482 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
483 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
484 octave_is_NA (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
485 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
486 return (octave_is_NA (real (x)) || octave_is_NA (imag (x))); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
487 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
488 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
489 bool |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
490 octave_is_NaN_or_NA (const FloatComplex& x) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
491 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
492 return (xisnan (real (x)) || xisnan (imag (x))); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
493 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
494 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
495 // (complex, complex) -> complex mappers. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
496 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
497 // FIXME: need to handle NA too? |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
498 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
499 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
500 xmin (const FloatComplex& x, const FloatComplex& y) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
501 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
502 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
503 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
504 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
505 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
506 xmax (const FloatComplex& x, const FloatComplex& y) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
507 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
508 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
509 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
510 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
511 Complex |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
512 rc_acos (double x) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
513 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
514 return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (acos (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
515 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
516 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
517 FloatComplex |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
518 rc_acos (float x) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
519 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
520 return fabsf (x) > 1.0f ? acos (FloatComplex (x)) : FloatComplex (acosf (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
521 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
522 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
523 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
524 rc_acosh (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
525 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
526 return x < 1.0 ? acosh (Complex (x)) : Complex (acosh (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
527 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
528 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
529 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
530 rc_acosh (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
531 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
532 return x < 1.0f ? acosh (FloatComplex (x)) : FloatComplex (acoshf (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
533 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
534 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
535 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
536 rc_asin (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
537 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
538 return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (asin (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
539 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
540 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
541 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
542 rc_asin (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
543 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
544 return fabsf (x) > 1.0f ? asin (FloatComplex (x)) : FloatComplex (asinf (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
545 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
546 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
547 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
548 rc_atanh (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
549 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
550 return fabs (x) > 1.0 ? atanh (Complex (x)) : Complex (atanh (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
551 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
552 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
553 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
554 rc_atanh (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
555 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
556 return fabsf (x) > 1.0f ? atanh (FloatComplex (x)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
557 : FloatComplex (atanhf (x)); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
558 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
559 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
560 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
561 rc_log (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
562 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
563 const double pi = 3.14159265358979323846; |
19570
264ff6bf7475
use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
564 return x < 0.0 ? Complex (gnulib::log (-x), pi) : Complex (gnulib::log (x)); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
565 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
566 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
567 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
568 rc_log (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
569 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
570 const float pi = 3.14159265358979323846f; |
19570
264ff6bf7475
use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
571 return (x < 0.0f |
264ff6bf7475
use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
572 ? FloatComplex (gnulib::logf (-x), pi) |
264ff6bf7475
use gnulib:: namespace for log, logf, localtime, and gmtime
John W. Eaton <jwe@octave.org>
parents:
19037
diff
changeset
|
573 : FloatComplex (gnulib::logf (x))); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
574 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
575 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
576 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
577 rc_log2 (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
578 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
579 const double pil2 = 4.53236014182719380962; // = pi / log(2) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
580 return x < 0.0 ? Complex (xlog2 (-x), pil2) : Complex (xlog2 (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
581 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
582 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
583 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
584 rc_log2 (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
585 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
586 const float pil2 = 4.53236014182719380962f; // = pi / log(2) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
587 return x < 0.0f ? FloatComplex (xlog2 (-x), pil2) : FloatComplex (xlog2 (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
588 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
589 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
590 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
591 rc_log10 (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
592 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
593 const double pil10 = 1.36437635384184134748; // = pi / log(10) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
594 return x < 0.0 ? Complex (log10 (-x), pil10) : Complex (log10 (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
595 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
596 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
597 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
598 rc_log10 (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
599 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
600 const float pil10 = 1.36437635384184134748f; // = pi / log(10) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
601 return x < 0.0f ? FloatComplex (log10 (-x), pil10) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
602 : FloatComplex (log10f (x)); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
603 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
604 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
605 Complex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
606 rc_sqrt (double x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
607 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
608 return x < 0.0 ? Complex (0.0, sqrt (-x)) : Complex (sqrt (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
609 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
610 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
611 FloatComplex |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
612 rc_sqrt (float x) |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
613 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
614 return x < 0.0f ? FloatComplex (0.0f, sqrtf (-x)) : FloatComplex (sqrtf (x)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
615 } |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
616 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
617 bool |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
618 xnegative_sign (double x) |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
619 { |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
620 return __lo_ieee_signbit (x); |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
621 } |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
622 |
11212
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
623 bool |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
624 xnegative_sign (float x) |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
625 { |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
626 return __lo_ieee_float_signbit (x); |
ce27d6f4e134
use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents:
11211
diff
changeset
|
627 } |
11211
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
628 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
629 // Convert X to the nearest integer value. Should not pass NaN to |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
630 // this function. |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
631 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
632 // Sometimes you need a large integer, but not always. |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
633 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
634 octave_idx_type |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
635 NINTbig (double x) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
636 { |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
637 if (x > std::numeric_limits<octave_idx_type>::max ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
638 return std::numeric_limits<octave_idx_type>::max (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
639 else if (x < std::numeric_limits<octave_idx_type>::min ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
640 return std::numeric_limits<octave_idx_type>::min (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
641 else |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
642 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
643 } |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
644 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
645 octave_idx_type |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
646 NINTbig (float x) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
647 { |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
648 if (x > std::numeric_limits<octave_idx_type>::max ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
649 return std::numeric_limits<octave_idx_type>::max (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
650 else if (x < std::numeric_limits<octave_idx_type>::min ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
651 return std::numeric_limits<octave_idx_type>::min (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
652 else |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
653 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
654 } |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
655 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
656 int |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
657 NINT (double x) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
658 { |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
659 if (x > std::numeric_limits<int>::max ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
660 return std::numeric_limits<int>::max (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
661 else if (x < std::numeric_limits<int>::min ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
662 return std::numeric_limits<int>::min (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
663 else |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
664 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
665 } |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
666 |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
667 int |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
668 NINT (float x) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
669 { |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
670 if (x > std::numeric_limits<int>::max ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
671 return std::numeric_limits<int>::max (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
672 else if (x < std::numeric_limits<int>::min ()) |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
673 return std::numeric_limits<int>::min (); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
674 else |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
675 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
2554b4a0806e
use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
676 } |