annotate liboctave/numeric/lo-mappers.cc @ 30867:014030798d5e stable

Avoid issues when converting large integers to floating point (bug #62212). * libinterp/corefcn/oct-stream.cc (get_size), libinterp/corefcn/xpow.cc (xisint), libinterp/octave-value/ov-base.cc (INT_CONV_METHOD), libinterp/octave-value/ov.cc (check_colon_operand, range_numel (T, double, T)), liboctave/numeric/lo-mappers.cc (nint_big, nint), liboctave/util/oct-inttypes.cc (emulate_mop, operator - (const double, const octave_uint64)), liboctave/util/oct-string.cc (rational_approx): Take into account that the maximum value of (signed or unsigned) integers might change its value if converted to floating point. In comparisons, check against the first value *outside* the range of the integer type instead of the last value *inside* its range.
author Markus Mützel <markus.muetzel@gmx.de>
date Mon, 28 Mar 2022 19:27:35 +0200
parents 796f54d4ddbf
children e88a07dec498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21232
diff changeset
27 # include "config.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
28 #endif
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
29
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
30 #include "lo-mappers.h"
3121
923049908004 [project @ 1997-12-01 00:01:00 by jwe]
jwe
parents: 3092
diff changeset
31 #include "lo-specfun.h"
23815
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
32 #include "math-wrappers.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
33
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
34 // 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
35 //
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
36 // 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
37 // gnulib:: out of lo-mappers.h.
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
38 //
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21786
diff changeset
39 // 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
40 // 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
41
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
42 namespace octave
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
43 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
44 namespace math
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
45 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
46 bool
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
47 isna (double x)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
48 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
49 return lo_ieee_is_NA (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
50 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
51
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
52 bool
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
53 isna (const Complex& x)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
54 {
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
55 return (isna (std::real (x)) || isna (std::imag (x)));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
56 }
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
57
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
58 bool
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
59 isna (float x)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
60 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
61 return lo_ieee_is_NA (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
62 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
63
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
64 bool
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
65 isna (const FloatComplex& x)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
66 {
23619
6ed4d6e306ba maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents: 23564
diff changeset
67 return (isna (std::real (x)) || isna (std::imag (x)));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
68 }
13737
30414ff19d5e Use copysignf module from gnulib.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11586
diff changeset
69
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
70 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
71 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
72 {
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
73 return (isnan (std::real (x)) || isnan (std::imag (x)));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
74 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
75
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
76 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
77 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
78 {
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
79 return (isnan (std::real (x)) || isnan (std::imag (x)));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
80 }
11525
ab231f944252 avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
81
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
82 // Matlab returns a different phase for acos, asin then std library
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
83 // which requires a small function to remap the phase.
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
84 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
85 acos (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
86 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
87 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
88
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
89 if (std::imag (x) == 0.0 && std::real (x) > 1.0)
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
90 return std::conj (y);
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
91 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
92 return y;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
93 }
11237
110e570e5f8d keep gnulib out of lo-mappers.h
John W. Eaton <jwe@octave.org>
parents: 11212
diff changeset
94
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
95 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
96 acos (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
97 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
98 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
99
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
100 if (std::imag (x) == 0.0f && std::real (x) > 1.0f)
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
101 return std::conj (y);
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
102 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
103 return y;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
104 }
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 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
107 asin (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
108 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
109 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
110
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
111 if (std::imag (x) == 0.0 && std::real (x) > 1.0)
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
112 return std::conj (y);
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
113 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
114 return y;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
115 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
116
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
117 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
118 asin (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
119 {
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
120 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
121
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
122 if (std::imag (x) == 0.0f && std::real (x) > 1.0f)
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
123 return std::conj (y);
21945
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
124 else
e9765b62d4e8 Use C++11 standard complex trig functions when available (bug #44310, bug #45507)
Mike Miller <mtmiller@octave.org>
parents: 21942
diff changeset
125 return y;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
126 }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
127
23815
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
128 double frexp (double x, int *expptr)
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
129 {
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
130 return octave_frexp_wrapper (x, expptr);
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
131 }
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
132
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
133 float frexp (float x, int *expptr)
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
134 {
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
135 return octave_frexpf_wrapper (x, expptr);
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
136 }
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
137
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
138 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
139 log2 (const Complex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
140 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
141 return std::log (x) / M_LN2;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
142 }
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
143
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
144 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 log2 (const FloatComplex& x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
146 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
147 return std::log (x) / static_cast<float> (M_LN2);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
148 }
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
149
23815
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
150 double
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
151 log2 (double x, int& exp)
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
152 {
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
153 return frexp (x, &exp);
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
154 }
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
155
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
156 float
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
157 log2 (float x, int& exp)
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
158 {
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
159 return frexp (x, &exp);
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
160 }
4d11ada80395 Restore using gnulib wrapper for frexp until MinGW C library is fixed (bug #51630).
Rik <rik@octave.org>
parents: 23761
diff changeset
161
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
162 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
163 log2 (const Complex& x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
164 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
165 double ax = std::abs (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
166 double lax = log2 (ax, exp);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
167 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
168 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
169
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
170 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
171 log2 (const FloatComplex& x, int& exp)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
172 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
173 float ax = std::abs (x);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
174 float lax = log2 (ax, exp);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
175 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
176 }
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 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
179 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
180
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
181 // 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
182
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
183 octave_idx_type
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
184 nint_big (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
185 {
30867
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
186 static const double out_of_range_top
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
187 = static_cast<double>(std::numeric_limits<octave_idx_type>::max ())+1.;
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
188 if (x >= out_of_range_top)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
189 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
190 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
191 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
192 else
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
193 return static_cast<octave_idx_type> ((x > 0.0) ? (x + 0.5)
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
194 : (x - 0.5));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
195 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
196
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
197 octave_idx_type
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
198 nint_big (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
199 {
30867
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
200 static const float out_of_range_top
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
201 = static_cast<float>(std::numeric_limits<octave_idx_type>::max ())+1.;
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
202 if (x >= out_of_range_top)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
203 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
204 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
205 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
206 else
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
207 return static_cast<octave_idx_type> ((x > 0.0f) ? (x + 0.5f)
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
208 : (x - 0.5f));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
209 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
210
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
211 int
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
212 nint (double x)
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
213 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
214 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
215 return std::numeric_limits<int>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
216 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
217 return std::numeric_limits<int>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
218 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
219 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
220 }
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
221
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
222 int
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
223 nint (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
224 {
30867
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
225 static const float out_of_range_top
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
226 = static_cast<float>(std::numeric_limits<int>::max ()) + 1.;
014030798d5e Avoid issues when converting large integers to floating point (bug #62212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
227 if (x >= out_of_range_top)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
228 return std::numeric_limits<int>::max ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
229 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
230 return std::numeric_limits<int>::min ();
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
231 else
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
232 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
233 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
234
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
235 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
236 rc_acos (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
237 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
238 return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (std::acos (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
239 }
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
240
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
241 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
242 rc_acos (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
243 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
244 return fabsf (x) > 1.0f ? acos (FloatComplex (x))
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
245 : FloatComplex (std::acos (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
246 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
247
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
248 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
249 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
250 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
251 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
252 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
253
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
254 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
255 rc_acosh (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
256 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
257 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
258 }
19242
ba7e42dea4b2 Fix returned phase of asin, acos outside principal branch (bug #43349).
Rik <rik@octave.org>
parents: 18928
diff changeset
259
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
260 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
261 rc_asin (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
262 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
263 return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (std::asin (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
264 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
265
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
266 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
267 rc_asin (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
268 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
269 return fabsf (x) > 1.0f ? asin (FloatComplex (x))
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
270 : FloatComplex (::asinf (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
271 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
272
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
273 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
274 rc_atanh (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
275 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
276 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
277 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
278
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
279 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
280 rc_atanh (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
281 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
282 return fabsf (x) > 1.0f ? atanh (FloatComplex (x))
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
283 : FloatComplex (atanh (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
284 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
285
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
286 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
287 rc_log (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
288 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
289 return x < 0.0 ? Complex (std::log (-x), M_PI) : Complex (std::log (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
290 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
291
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
292 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
293 rc_log (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
294 {
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
295 return x < 0.0f ? FloatComplex (std::log (-x), static_cast<float> (M_PI))
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
296 : FloatComplex (std::log (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
297 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
298
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
299 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
300 rc_log2 (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
301 {
23761
102049c83e7c Use constexpr rather than just const to provide hint to compiler.
Rik <rik@octave.org>
parents: 23733
diff changeset
302 constexpr double PI_LN2 = 4.53236014182719380962; // = pi / log(2)
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
303 return x < 0.0 ? Complex (log2 (-x), PI_LN2) : Complex (log2 (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
304 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
305
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
306 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
307 rc_log2 (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
308 {
23761
102049c83e7c Use constexpr rather than just const to provide hint to compiler.
Rik <rik@octave.org>
parents: 23733
diff changeset
309 constexpr float PI_LN2 = 4.53236014182719380962f; // = pi / log(2)
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
310 return x < 0.0f ? FloatComplex (log2 (-x), PI_LN2)
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
311 : FloatComplex (log2 (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
312 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
313
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
314 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
315 rc_log10 (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
316 {
23761
102049c83e7c Use constexpr rather than just const to provide hint to compiler.
Rik <rik@octave.org>
parents: 23733
diff changeset
317 constexpr double PI_LN10 = 1.36437635384184134748; // = pi / log(10)
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
318 return x < 0.0 ? Complex (log10 (-x), PI_LN10) : Complex (log10 (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
319 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
320
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
321 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
322 rc_log10 (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
323 {
23761
102049c83e7c Use constexpr rather than just const to provide hint to compiler.
Rik <rik@octave.org>
parents: 23733
diff changeset
324 constexpr float PI_LN10 = 1.36437635384184134748f; // = pi / log(10)
23682
6fe13cd3543c Clean up lo-mappers.h, lo-mappers.cc.
Rik <rik@octave.org>
parents: 23665
diff changeset
325 return x < 0.0f ? FloatComplex (log10 (-x), PI_LN10)
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
326 : FloatComplex (log10f (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
327 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
328
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
329 Complex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
330 rc_sqrt (double x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
331 {
23649
aabf6cd222ac Use sqrt from C++ std library in liboctave.
Rik <rik@octave.org>
parents: 23643
diff changeset
332 return x < 0.0 ? Complex (0.0, std::sqrt (-x)) : Complex (std::sqrt (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
333 }
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
334
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
335 FloatComplex
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
336 rc_sqrt (float x)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
337 {
23649
aabf6cd222ac Use sqrt from C++ std library in liboctave.
Rik <rik@octave.org>
parents: 23643
diff changeset
338 return x < 0.0f ? FloatComplex (0.0f, std::sqrt (-x))
aabf6cd222ac Use sqrt from C++ std library in liboctave.
Rik <rik@octave.org>
parents: 23643
diff changeset
339 : FloatComplex (std::sqrt (x));
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
340 }
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
341 }
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
342 }