annotate liboctave/numeric/lo-mappers.cc @ 22079:e0dbd81fd9b1

provide wrapper for frexp and frexpf (bug #48363) * bootstrap.conf (gnulib_modules): Add modules frexp and frexpf. * liboctave/wrappers/math-wrappers.c, liboctave/wrappers/math-wrappers.h: New files. * liboctave/wrappers/module.mk: Add math-wrappers.{c,h}. * lo-mappers.cc, lo-mappers.h (octave::math::frexp): New functions. (octave::math::log2): Use them instead of std::frexp. * data.cc (Feps): Use octave::math::frexp instead of std::frexp. * oct-inttypes.cc (dblesplit): Likewise.
author Mike Miller <mtmiller@octave.org>
date Sun, 03 Jul 2016 09:54:43 -0700
parents e9765b62d4e8
children edcad35c364f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
1 /*
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19377
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
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
5
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
7
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
11 option) any later version.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
12
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
16 for more details.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
17
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6596
diff changeset
20 <http://www.gnu.org/licenses/>.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
21
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
22 */
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21232
diff changeset
25 # include "config.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
26 #endif
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
27
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
28 #include <cfloat>
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3248
diff changeset
29
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
30 #include "lo-error.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
31 #include "lo-ieee.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
32 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7017
diff changeset
33 #include "lo-math.h"
3121
923049908004 [project @ 1997-12-01 00:01:00 by jwe]
jwe
parents: 3092
diff changeset
34 #include "lo-specfun.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
35 #include "lo-utils.h"
22079
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
36 #include "math-wrappers.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
37 #include "oct-cmplx.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
38
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
39 #include "f77-fcn.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
40
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
41 // FIXME: We used to have this situation:
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
42 //
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
43 // Functions that forward to gnulib belong here so we can keep
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
44 // gnulib:: out of lo-mappers.h.
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
45 //
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
46 // but now we just use std:: and explicit wrappers in C++ code so maybe
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
47 // some of the forwarding functions can be defined inline here.
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
48
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
49 namespace octave
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
50 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
51 namespace math
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
52 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
53 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
54 is_NA (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
55 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
56 return lo_ieee_is_NA (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
57 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
58
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
59 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
60 is_NA (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
61 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
62 return (is_NA (real (x)) || is_NA (imag (x)));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
63 }
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
64
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
65 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
66 is_NA (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
67 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
68 return lo_ieee_is_NA (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
69 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
70
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
71 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
72 is_NA (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
73 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
74 return (is_NA (real (x)) || is_NA (imag (x)));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
75 }
13737
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
76
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
77 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
78 is_NaN_or_NA (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
79 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
80 return (isnan (real (x)) || isnan (imag (x)));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
81 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
82
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
83 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
84 is_NaN_or_NA (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
85 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
86 return (isnan (real (x)) || isnan (imag (x)));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
87 }
11525
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
88
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
89 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
90 acos (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
91 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
92 #if defined (HAVE_COMPLEX_STD_ACOS)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
93 Complex y = std::acos (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
94
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
95 if (imag (x) == 0.0 && real (x) > 1.0)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
96 return conj (y);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
97 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
98 return y;
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
99 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
100 static Complex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
101
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
102 Complex tmp;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
103
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
104 if (imag (x) == 0.0)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
105 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
106 // If the imaginary part of X is 0, then avoid generating an
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
107 // imaginary part of -0 for the expression 1-x*x.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
108 // This effectively chooses the same phase of the branch cut as Matlab.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
109 double xr = real (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
110 tmp = Complex (1.0 - xr*xr);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
111 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
112 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
113 tmp = 1.0 - x*x;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
114
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
115 return -i * log (x + i * sqrt (tmp));
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
116 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
117 }
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
118
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
119 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
120 acos (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
121 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
122 #if defined (HAVE_COMPLEX_STD_ACOS)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
123 FloatComplex y = std::acos (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
124
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
125 if (imag (x) == 0.0f && real (x) > 1.0f)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
126 return conj (y);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
127 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
128 return y;
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
129 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
130 static FloatComplex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
131
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
132 FloatComplex tmp;
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
133
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
134 if (imag (x) == 0.0f)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
135 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
136 // If the imaginary part of X is 0, then avoid generating an
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
137 // imaginary part of -0 for the expression 1-x*x.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
138 // This effectively chooses the same phase of the branch cut as Matlab.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
139 float xr = real (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
140 tmp = FloatComplex (1.0f - xr*xr);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
141 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
142 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
143 tmp = 1.0f - x*x;
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
144
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 return -i * log (x + i * sqrt (tmp));
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
146 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
147 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
148
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
149 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
150 asin (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
151 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
152 #if defined (HAVE_COMPLEX_STD_ASIN)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
153 Complex y = std::asin (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
154
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
155 if (imag (x) == 0.0 && real (x) > 1.0)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
156 return conj (y);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
157 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
158 return y;
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
159 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
160 static Complex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
161
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
162 Complex tmp;
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
163
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
164 if (imag (x) == 0.0)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
165 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
166 // If the imaginary part of X is 0, then avoid generating an
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
167 // imaginary part of -0 for the expression 1-x*x.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
168 // This effectively chooses the same phase of the branch cut as Matlab.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
169 double xr = real (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
170 tmp = Complex (1.0 - xr*xr);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
171 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
172 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
173 tmp = 1.0 - x*x;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
174
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
175 return -i * log (i*x + sqrt (tmp));
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
176 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
177 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
178
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
179 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
180 asin (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
181 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
182 #if defined (HAVE_COMPLEX_STD_ASIN)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
183 FloatComplex y = std::asin (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
184
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
185 if (imag (x) == 0.0f && real (x) > 1.0f)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
186 return conj (y);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
187 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
188 return y;
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
189 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
190 static FloatComplex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
191
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
192 FloatComplex tmp;
4984
98e4b7da360a [project @ 2004-09-10 14:02:41 by jwe]
jwe
parents: 4968
diff changeset
193
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
194 if (imag (x) == 0.0f)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
195 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
196 // If the imaginary part of X is 0, then avoid generating an
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
197 // imaginary part of -0 for the expression 1-x*x.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
198 // This effectively chooses the same phase of the branch cut as Matlab.
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
199 float xr = real (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
200 tmp = FloatComplex (1.0f - xr*xr);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
201 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
202 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
203 tmp = 1.0f - x*x;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
204
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
205 return -i * log (i*x + sqrt (tmp));
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
206 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
207 }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
208
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
209 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
210 atan (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
211 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
212 #if defined (HAVE_COMPLEX_STD_ATAN)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
213 return std::atan (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
214 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
215 static Complex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
216
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
217 return i * log ((i + x) / (i - x)) / 2.0;
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
218 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
219 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
220
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
221 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
222 atan (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
223 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
224 #if defined (HAVE_COMPLEX_STD_ATAN)
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
225 return std::atan (x);
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
226 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
227 static FloatComplex i (0, 1);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
228
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
229 return i * log ((i + x) / (i - x)) / 2.0f;
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
230 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
231 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
232
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
233 double log2 (double x) { return std::log2 (x); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
234 float log2 (float x) { return std::log2 (x); }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
235
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
236 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
237 log2 (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
238 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
239 #if defined (M_LN2)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
240 static double ln2 = M_LN2;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
241 #else
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
242 static double ln2 = std::log (2.0);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
243 #endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
244 return std::log (x) / ln2;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
245 }
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
246
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
247 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
248 log2 (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
249 {
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
250 #if defined (M_LN2)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
251 static float ln2 = M_LN2;
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
252 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
253 static float ln2 = log (2.0f);
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
254 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
255 return std::log (x) / ln2;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
256 }
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
257
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
258 double
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
259 log2 (double x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
260 {
22079
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
261 return frexp (x, &exp);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
262 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
263
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
264 float
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
265 log2 (float x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
266 {
22079
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
267 return frexp (x, &exp);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
268 }
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
269
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
270 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
271 log2 (const Complex& x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
272 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
273 double ax = std::abs (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
274 double lax = log2 (ax, exp);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
275 return (ax != lax) ? (x / ax) * lax : x;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
276 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
277
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
278 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
279 log2 (const FloatComplex& x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
280 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
281 float ax = std::abs (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
282 float lax = log2 (ax, exp);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
283 return (ax != lax) ? (x / ax) * lax : x;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
284 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
285
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
286 double
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
287 exp2 (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
288 {
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
289 #if defined (HAVE_EXP2)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
290 return ::exp2 (x);
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
291 #else
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20791
diff changeset
292 # if defined (M_LN2)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
293 static double ln2 = M_LN2;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
294 # else
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
295 static double ln2 = std::log (2.0);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
296 # endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
297 return exp (x * ln2);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
298 #endif
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
299 }
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
300
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
301 float
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
302 exp2 (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
303 {
15452
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15409
diff changeset
304 #if defined (HAVE_EXP2F)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
305 return exp2f (x);
15452
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15409
diff changeset
306 #elif defined (HAVE_EXP2)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
307 return ::exp2 (x);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
308 #else
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20791
diff changeset
309 # if defined (M_LN2)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
310 static float ln2 = M_LN2;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
311 # else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
312 static float ln2 = log2 (2.0f);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
313 # endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
314 return exp (x * ln2);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
315 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
316 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
317
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
318 double copysign (double x, double y) { return std::copysign (x, y); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
319 float copysign (float x, float y) { return std::copysign (x, y); }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
320
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
321 double signbit (double x) { return std::signbit (x); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
322 float signbit (float x) { return std::signbit (x); }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
323
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
324 bool negative_sign (double x) { return __lo_ieee_signbit (x); }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
325 bool negative_sign (float x) { return __lo_ieee_float_signbit (x); }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
326
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
327 double trunc (double x) { return std::trunc (x); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
328 float trunc (float x) { return std::trunc (x); }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
329
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
330 double floor (double x) { return std::floor (x); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
331 float floor (float x) { return std::floor (x); }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
332
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
333 double round (double x) { return std::round (x); }
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
334 float round (float x) { return std::round (x); }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
335
22079
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
336 double frexp (double x, int *expptr)
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
337 {
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
338 return octave_frexp_wrapper (x, expptr);
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
339 }
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
340
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
341 float frexp (float x, int *expptr)
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
342 {
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
343 return octave_frexpf_wrapper (x, expptr);
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
344 }
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 21945
diff changeset
345
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
346 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
347 isnan (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
348 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
349 #if defined (HAVE_CMATH_ISNAN)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
350 return std::isnan (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
351 #else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
352 return lo_ieee_isnan (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
353 #endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
354 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
355
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
356 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
357 isnan (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
358 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
359 #if defined (HAVE_CMATH_ISNANF)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
360 return std::isnan (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
361 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
362 return lo_ieee_isnan (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
363 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
364 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
365
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
366 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
367 finite (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
368 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
369 #if defined (HAVE_CMATH_ISFINITE)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
370 return std::isfinite (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
371 #else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
372 return lo_ieee_finite (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
373 #endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
374 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
375
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
376 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
377 finite (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
378 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
379 #if defined (HAVE_CMATH_ISFINITEF)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
380 return std::isfinite (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
381 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
382 return lo_ieee_finite (x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
383 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
384 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
385
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
386 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
387 isinf (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
388 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
389 #if defined (HAVE_CMATH_ISINF)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
390 return std::isinf (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
391 #else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
392 return lo_ieee_isinf (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
393 #endif
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
394 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
395
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
396 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
397 isinf (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
398 {
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
399 #if defined (HAVE_CMATH_ISINFF)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
400 return std::isinf (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
401 #else
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
402 return lo_ieee_isinf (x);
21232
b8cf410b5c88 eliminate feature tests from lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 21231
diff changeset
403 #endif
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
404 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
405
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
406 // Sometimes you need a large integer, but not always.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
407
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
408 octave_idx_type
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
409 nint_big (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
410 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
411 if (x > std::numeric_limits<octave_idx_type>::max ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
412 return std::numeric_limits<octave_idx_type>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
413 else if (x < std::numeric_limits<octave_idx_type>::min ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
414 return std::numeric_limits<octave_idx_type>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
415 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
416 return static_cast<octave_idx_type> ((x > 0.0) ? (x + 0.5) : (x - 0.5));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
417 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
418
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
419 octave_idx_type
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
420 nint_big (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
421 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
422 if (x > std::numeric_limits<octave_idx_type>::max ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
423 return std::numeric_limits<octave_idx_type>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
424 else if (x < std::numeric_limits<octave_idx_type>::min ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
425 return std::numeric_limits<octave_idx_type>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
426 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
427 return static_cast<octave_idx_type> ((x > 0.0f) ? (x + 0.5f) : (x - 0.5f));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
428 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
429
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
430 int
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
431 nint (double x)
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
432 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
433 if (x > std::numeric_limits<int>::max ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
434 return std::numeric_limits<int>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
435 else if (x < std::numeric_limits<int>::min ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
436 return std::numeric_limits<int>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
437 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
438 return static_cast<int> ((x > 0.0) ? (x + 0.5) : (x - 0.5));
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
439 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
440
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
441 int
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
442 nint (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
443 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
444 if (x > std::numeric_limits<int>::max ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
445 return std::numeric_limits<int>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
446 else if (x < std::numeric_limits<int>::min ())
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
447 return std::numeric_limits<int>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
448 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
449 return static_cast<int> ((x > 0.0f) ? (x + 0.5f) : (x - 0.5f));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
450 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
451
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
452 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
453 rc_acos (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
454 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
455 return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (::acos (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
456 }
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
457
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
458 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
459 rc_acos (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
460 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
461 return fabsf (x) > 1.0f ? acos (FloatComplex (x)) : FloatComplex (::acosf (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
462 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
463
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
464 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
465 rc_acosh (double x)
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
466 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
467 return x < 1.0 ? acosh (Complex (x)) : Complex (acosh (x));
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
468 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
469
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
470 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
471 rc_acosh (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
472 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
473 return x < 1.0f ? acosh (FloatComplex (x)) : FloatComplex (acosh (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
474 }
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
475
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
476 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
477 rc_asin (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
478 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
479 return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (::asin (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
480 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
481
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
482 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
483 rc_asin (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
484 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
485 return fabsf (x) > 1.0f ? asin (FloatComplex (x)) : FloatComplex (::asinf (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
486 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
487
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
488 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
489 rc_atanh (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
490 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
491 return fabs (x) > 1.0 ? atanh (Complex (x)) : Complex (atanh (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
492 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
493
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
494 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
495 rc_atanh (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
496 {
21786
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
497 return fabsf (x) > 1.0f ? atanh (FloatComplex (x)) : FloatComplex (atanh (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
498 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
499
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
500 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
501 rc_log (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
502 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
503 const double pi = 3.14159265358979323846;
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
504 return x < 0.0 ? Complex (std::log (-x), pi) : Complex (std::log (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
505 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
506
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
507 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
508 rc_log (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
509 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
510 const float pi = 3.14159265358979323846f;
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
511 return x < 0.0f ? FloatComplex (std::log (-x), pi) : FloatComplex (std::log (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
512 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
513
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
514 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
515 rc_log2 (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
516 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
517 const double pil2 = 4.53236014182719380962; // = pi / log(2)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
518 return x < 0.0 ? Complex (log2 (-x), pil2) : Complex (log2 (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
519 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
520
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
521 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
522 rc_log2 (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
523 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
524 const float pil2 = 4.53236014182719380962f; // = pi / log(2)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
525 return x < 0.0f ? FloatComplex (log2 (-x), pil2) : FloatComplex (log2 (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
526 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
527
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
528 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
529 rc_log10 (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
530 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
531 const double pil10 = 1.36437635384184134748; // = pi / log(10)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
532 return x < 0.0 ? Complex (log10 (-x), pil10) : Complex (log10 (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
533 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
534
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
535 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
536 rc_log10 (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
537 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
538 const float pil10 = 1.36437635384184134748f; // = pi / log(10)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
539 return x < 0.0f ? FloatComplex (log10 (-x), pil10) : FloatComplex (log10f (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
540 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
541
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
542 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
543 rc_sqrt (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
544 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
545 return x < 0.0 ? Complex (0.0, sqrt (-x)) : Complex (sqrt (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
546 }
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
547
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
548 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
549 rc_sqrt (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
550 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
551 return x < 0.0f ? FloatComplex (0.0f, sqrtf (-x)) : FloatComplex (sqrtf (x));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
552 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
553 }
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
554 }