annotate liboctave/lo-mappers.cc @ 11212:ce27d6f4e134

use templates and inline for more lo-mappers functionos
author John W. Eaton <jwe@octave.org>
date Tue, 09 Nov 2010 04:24:26 -0500
parents 2554b4a0806e
children 110e570e5f8d
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8904
diff changeset
4 2005, 2006, 2007, 2008, 2009 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10459
diff changeset
5 Copyright (C) 2010 VZLU Prague
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
6
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
8
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
9 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
10 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
11 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
12 option) any later version.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
13
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
14 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
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
16 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
17 for more details.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
18
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
19 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
20 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
21 <http://www.gnu.org/licenses/>.
1967
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 */
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
24
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
26 #include <config.h>
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
27 #endif
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
28
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
29 #include <cfloat>
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3248
diff changeset
30
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
31 #include "lo-error.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
32 #include "lo-ieee.h"
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
33 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7017
diff changeset
34 #include "lo-math.h"
3121
923049908004 [project @ 1997-12-01 00:01:00 by jwe]
jwe
parents: 3092
diff changeset
35 #include "lo-specfun.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
36 #include "lo-utils.h"
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
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
41 // double -> double mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
42
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
43 double
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
44 xroundb (double x)
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
45 {
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
46 double t = xround (x);
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
47
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
48 if (fabs (x - t) == 0.5)
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
49 t = 2 * xtrunc (0.5 * t);
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
50
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
51 return t;
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
52 }
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
53
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7231
diff changeset
54 double
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
55 signum (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
56 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
57 double tmp = 0.0;
4984
98e4b7da360a [project @ 2004-09-10 14:02:41 by jwe]
jwe
parents: 4968
diff changeset
58
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
59 if (x < 0.0)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
60 tmp = -1.0;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
61 else if (x > 0.0)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
62 tmp = 1.0;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
63
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
64 return xisnan (x) ? octave_NaN : tmp;
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
65 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
66
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
67 double
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
68 xlog2 (double x)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
69 {
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
70 #if defined (HAVE_LOG2)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
71 return log2 (x);
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
72 #else
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
73 #if defined (M_LN2)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
74 static double ln2 = M_LN2;
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
75 #else
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
76 static double ln2 = log (2);
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
77 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
78
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
79 return log (x) / ln2;
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
80 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
81 }
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
82
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
83 Complex
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
84 xlog2 (const Complex& x)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
85 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
86 #if defined (M_LN2)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
87 static double ln2 = M_LN2;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
88 #else
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
89 static double ln2 = log (2);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
90 #endif
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
91
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
92 return std::log (x) / ln2;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
93 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
94
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
95 double
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
96 xexp2 (double x)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
97 {
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
98 #if defined (HAVE_EXP2)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
99 return exp2 (x);
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
100 #else
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
101 #if defined (M_LN2)
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
102 static double ln2 = M_LN2;
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
103 #else
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
104 static double ln2 = log (2);
5904
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
105 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
106
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
107 return exp (x * ln2);
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
108 #endif
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
109 }
80d3933fb8b6 [project @ 2006-07-26 17:19:10 by jwe]
jwe
parents: 5775
diff changeset
110
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
111 double
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
112 xlog2 (double x, int& exp)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
113 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
114 return frexp (x, &exp);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
115 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
116
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
117 Complex
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
118 xlog2 (const Complex& x, int& exp)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
119 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
120 double ax = std::abs (x);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
121 double lax = xlog2 (ax, exp);
9319
0d9178575dd7 fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
122 return (ax != lax) ? (x / ax) * lax : x;
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
123 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7707
diff changeset
124
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
125 // double -> bool mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
126
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
127 #if ! defined(HAVE_CMATH_ISNAN)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
128 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
129 xisnan (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
130 {
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
131 return lo_ieee_isnan (x);
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
132 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
133 #endif
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
134
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
135 #if ! defined(HAVE_CMATH_ISFINITE)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
136 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
137 xfinite (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
138 {
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
139 return lo_ieee_finite (x);
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
140 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
141 #endif
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
142
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
143 #if ! defined(HAVE_CMATH_ISINF)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
144 bool
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
145 xisinf (double x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
146 {
4074
a67f76924703 [project @ 2002-09-27 21:06:02 by jwe]
jwe
parents: 4065
diff changeset
147 return lo_ieee_isinf (x);
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
148 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
149 #endif
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
150
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
151 bool
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
152 octave_is_NA (double x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
153 {
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
154 return lo_ieee_is_NA (x);
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
155 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
156
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
157 bool
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
158 octave_is_NaN_or_NA (double x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
159 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5307
diff changeset
160 return lo_ieee_isnan (x);
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
161 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
162
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
163 // (double, double) -> double mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
164
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
165 // complex -> complex mappers.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
166
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
167 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
168 acos (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
169 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
170 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
171
6414
250eebbd7ccc [project @ 2007-03-15 16:04:52 by jwe]
jwe
parents: 5904
diff changeset
172 return -i * (log (x + i * (sqrt (1.0 - x*x))));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
173 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
174
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
175 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
176 acosh (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
177 {
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
178 return log (x + sqrt (x*x - 1.0));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
179 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
180
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
181 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
182 asin (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
183 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
184 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
185
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
186 return -i * log (i*x + sqrt (1.0 - x*x));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
187 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
188
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
189 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
190 asinh (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
191 {
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
192 return log (x + sqrt (x*x + 1.0));
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
193 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
194
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
195 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
196 atan (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
197 {
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
198 static Complex i (0, 1);
3056
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
199
b08a007edd15 [project @ 1997-06-16 02:12:15 by jwe]
jwe
parents: 3049
diff changeset
200 return i * log ((i + x) / (i - x)) / 2.0;
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
201 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
202
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
203 Complex
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
204 atanh (const Complex& x)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
205 {
3092
4bb976b250bf [project @ 1997-10-17 07:48:48 by jwe]
jwe
parents: 3069
diff changeset
206 return log ((1.0 + x) / (1.0 - x)) / 2.0;
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
207 }
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
208
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
209 // complex -> bool mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
210
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
211 bool
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
212 octave_is_NA (const Complex& x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
213 {
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
214 return (octave_is_NA (real (x)) || octave_is_NA (imag (x)));
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
215 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
216
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
217 bool
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
218 octave_is_NaN_or_NA (const Complex& x)
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
219 {
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5307
diff changeset
220 return (xisnan (real (x)) || xisnan (imag (x)));
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
221 }
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
222
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
223 // (complex, complex) -> complex mappers.
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
224
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5389
diff changeset
225 // FIXME -- need to handle NA too?
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3873
diff changeset
226
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
227 Complex
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
228 xmin (const Complex& x, const Complex& y)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
229 {
3757
574711ce9070 [project @ 2000-12-15 18:19:15 by jwe]
jwe
parents: 3268
diff changeset
230 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
231 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
232
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
233 Complex
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
234 xmax (const Complex& x, const Complex& y)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
235 {
3757
574711ce9070 [project @ 2000-12-15 18:19:15 by jwe]
jwe
parents: 3268
diff changeset
236 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
237 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3206
diff changeset
238
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
239
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
240 // float -> float mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
241
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
242 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
243 xroundb (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
244 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
245 float t = xround (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
246
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
247 if (fabsf (x - t) == 0.5)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
248 t = 2 * xtrunc (0.5 * t);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
249
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
250 return t;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
251 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
252
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
253 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
254 signum (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
255 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
256 float tmp = 0.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
257
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
258 if (x < 0.0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
259 tmp = -1.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
260 else if (x > 0.0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
261 tmp = 1.0;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
262
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
263 return xisnan (x) ? octave_Float_NaN : tmp;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
264 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
265
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
266 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
267 xlog2 (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
268 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
269 #if defined (HAVE_LOG2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
270 return log2 (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
271 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
272 #if defined (M_LN2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
273 static float ln2 = M_LN2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
274 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
275 static float ln2 = log2 (2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
276 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
277
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
278 return log (x) / ln2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
279 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
280 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
281
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
282 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
283 xlog2 (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
284 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
285 #if defined (M_LN2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
286 static float ln2 = M_LN2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
287 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
288 static float ln2 = log (2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
289 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
290
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
291 return std::log (x) / ln2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
292 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
293
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
294 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
295 xexp2 (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
296 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
297 #if defined (HAVE_EXP2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
298 return exp2 (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
299 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
300 #if defined (M_LN2)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
301 static float ln2 = M_LN2;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
302 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
303 static float ln2 = log2 (2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
304 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
305
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
306 return exp (x * ln2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
307 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
308 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
309
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
310 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
311 xlog2 (float x, int& exp)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
312 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
313 return frexpf (x, &exp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
314 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
315
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
316 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
317 xlog2 (const FloatComplex& x, int& exp)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
318 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
319 float ax = std::abs (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
320 float lax = xlog2 (ax, exp);
9319
0d9178575dd7 fix log2 with 2 outargs, loosen tests to meet IEEE
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
321 return (ax != lax) ? (x / ax) * lax : x;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
322 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
323
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
324 // float -> bool mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
325
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
326 #if ! defined(HAVE_CMATH_ISNANF)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
327 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
328 xisnan (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
329 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
330 return lo_ieee_isnan (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
331 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
332 #endif
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
333
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
334 #if ! defined(HAVE_CMATH_ISFINITEF)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
335 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
336 xfinite (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
337 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
338 return lo_ieee_finite (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
339 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
340 #endif
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
341
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
342 #if ! defined(HAVE_CMATH_ISINFF)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
343 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
344 xisinf (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
345 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
346 return lo_ieee_isinf (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
347 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
348 #endif
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
349
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
350 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
351 octave_is_NA (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
352 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
353 return lo_ieee_is_NA (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
354 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
355
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
356 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
357 octave_is_NaN_or_NA (float x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
358 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
359 return lo_ieee_isnan (x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
360 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
361
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
362 // (float, float) -> float mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
363
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
364 // complex -> complex mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
365
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
366 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
367 acos (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
368 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
369 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
370
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
371 return -i * (log (x + i * (sqrt (static_cast<float>(1.0) - x*x))));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
372 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
373
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
374 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
375 acosh (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
376 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
377 return log (x + sqrt (x*x - static_cast<float>(1.0)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
378 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
379
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
380 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
381 asin (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
382 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
383 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
384
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
385 return -i * log (i*x + sqrt (static_cast<float>(1.0) - x*x));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
386 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
387
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
388 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
389 asinh (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
390 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
391 return log (x + sqrt (x*x + static_cast<float>(1.0)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
392 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
393
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
394 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
395 atan (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
396 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
397 static FloatComplex i (0, 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
398
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
399 return i * log ((i + x) / (i - x)) / static_cast<float>(2.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
400 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
401
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
402 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
403 atanh (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
404 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
405 return log ((static_cast<float>(1.0) + x) / (static_cast<float>(1.0) - x)) / static_cast<float>(2.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
406 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
407
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
408 // complex -> bool mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
409
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
410 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
411 octave_is_NA (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
412 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
413 return (octave_is_NA (real (x)) || octave_is_NA (imag (x)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
414 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
415
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
416 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
417 octave_is_NaN_or_NA (const FloatComplex& x)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
418 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
419 return (xisnan (real (x)) || xisnan (imag (x)));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
420 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
421
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
422 // (complex, complex) -> complex mappers.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
423
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
424 // FIXME -- need to handle NA too?
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
425
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
426 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
427 xmin (const FloatComplex& x, const FloatComplex& y)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
428 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
429 return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
430 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
431
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
432 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
433 xmax (const FloatComplex& x, const FloatComplex& y)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
434 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
435 return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
436 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
437
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
438 Complex
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
439 rc_acos (double x)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
440 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
441 return fabs (x) > 1.0 ? acos (Complex (x)) : Complex (acos (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
442 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
443
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
444 FloatComplex
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
445 rc_acos (float x)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
446 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
447 return fabsf (x) > 1.0f ? acos (FloatComplex (x)) : FloatComplex (acosf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
448 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
449
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
450 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
451 rc_acosh (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
452 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
453 return x < 1.0 ? acosh (Complex (x)) : Complex (acosh (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
454 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
455
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
456 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
457 rc_acosh (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
458 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
459 return x < 1.0f ? acosh (FloatComplex (x)) : FloatComplex (acoshf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
460 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
461
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
462 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
463 rc_asin (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
464 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
465 return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (asin (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
466 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
467
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
468 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
469 rc_asin (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
470 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
471 return fabsf (x) > 1.0f ? asin (FloatComplex (x)) : FloatComplex (asinf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
472 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
473
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
474 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
475 rc_atanh (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
476 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
477 return fabs (x) > 1.0 ? atanh (Complex (x)) : Complex (atanh (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
478 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
479
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
480 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
481 rc_atanh (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
482 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
483 return fabsf (x) > 1.0f ? atanh (FloatComplex (x)) : FloatComplex (atanhf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
484 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
485
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
486 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
487 rc_log (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
488 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
489 const double pi = 3.14159265358979323846;
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
490 return x < 0.0 ? Complex (log (-x), pi) : Complex (log (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
491 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
492
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
493 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
494 rc_log (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
495 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
496 const float pi = 3.14159265358979323846f;
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
497 return x < 0.0f ? FloatComplex (logf (-x), pi) : FloatComplex (logf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
498 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
499
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
500 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
501 rc_log2 (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
502 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
503 const double pil2 = 4.53236014182719380962; // = pi / log(2)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
504 return x < 0.0 ? Complex (xlog2 (-x), pil2) : Complex (xlog2 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
505 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
506
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
507 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
508 rc_log2 (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
509 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
510 const float pil2 = 4.53236014182719380962f; // = pi / log(2)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
511 return x < 0.0f ? FloatComplex (xlog2 (-x), pil2) : FloatComplex (xlog2 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
512 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
513
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
514 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
515 rc_log10 (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
516 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
517 const double pil10 = 1.36437635384184134748; // = pi / log(10)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
518 return x < 0.0 ? Complex (log10 (-x), pil10) : Complex (log10 (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
519 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
520
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
521 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
522 rc_log10 (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
523 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
524 const float pil10 = 1.36437635384184134748f; // = pi / log(10)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
525 return x < 0.0f ? FloatComplex (log10 (-x), pil10) : FloatComplex (log10f (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
526 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
527
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
528 Complex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
529 rc_sqrt (double x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
530 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
531 return x < 0.0 ? Complex (0.0, sqrt (-x)) : Complex (sqrt (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
532 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
533
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
534 FloatComplex
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
535 rc_sqrt (float x)
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
536 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
537 return x < 0.0f ? FloatComplex (0.0f, sqrtf (-x)) : FloatComplex (sqrtf (x));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
538 }
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
539
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
540 bool
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
541 xnegative_sign (double x)
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
542 {
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
543 return __lo_ieee_signbit (x);
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
544 }
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
545
11212
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
546 bool
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
547 xnegative_sign (float x)
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
548 {
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
549 return __lo_ieee_float_signbit (x);
ce27d6f4e134 use templates and inline for more lo-mappers functionos
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
550 }
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
551
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
552 // Convert X to the nearest integer value. Should not pass NaN to
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
553 // this function.
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
554
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
555 // Sometimes you need a large integer, but not always.
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
556
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
557 octave_idx_type
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
558 NINTbig (double x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
559 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
560 if (x > std::numeric_limits<octave_idx_type>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
561 return std::numeric_limits<octave_idx_type>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
562 else if (x < std::numeric_limits<octave_idx_type>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
563 return std::numeric_limits<octave_idx_type>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
564 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
565 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
566 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
567
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
568 octave_idx_type
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
569 NINTbig (float x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
570 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
571 if (x > std::numeric_limits<octave_idx_type>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
572 return std::numeric_limits<octave_idx_type>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
573 else if (x < std::numeric_limits<octave_idx_type>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
574 return std::numeric_limits<octave_idx_type>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
575 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
576 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
577 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
578
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
579 int
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
580 NINT (double x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
581 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
582 if (x > std::numeric_limits<int>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
583 return std::numeric_limits<int>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
584 else if (x < std::numeric_limits<int>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
585 return std::numeric_limits<int>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
586 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
587 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
588 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
589
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
590 int
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
591 NINT (float x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
592 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
593 if (x > std::numeric_limits<int>::max ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
594 return std::numeric_limits<int>::max ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
595 else if (x < std::numeric_limits<int>::min ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
596 return std::numeric_limits<int>::min ();
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
597 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
598 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5));
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
599 }