annotate liboctave/lo-mappers.h @ 11211:2554b4a0806e

use templates for some lo-mappers functions
author John W. Eaton <jwe@octave.org>
date Tue, 09 Nov 2010 03:24:18 -0500
parents 94d9d412a2a0
children ce27d6f4e134
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, 2001, 2002, 2003, 2004, 2005,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7922
diff changeset
4 2006, 2007, 2008 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
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: 6108
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: 6108
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: 6108
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: 6108
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 #if !defined (octave_liboctave_mappers_h)
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
26 #define octave_liboctave_mappers_h 1
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
27
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
28 #include <limits>
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
29
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
30 #include "oct-cmplx.h"
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
31 #include "lo-math.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
32
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
33 // Double Precision
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
34 inline double xtrunc (double x) { return gnulib::trunc (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
35 inline double xcopysign (double x, double y) { return copysignf (x, y); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
36 inline double xfloor (double x) { return floor (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
37
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
38 extern OCTAVE_API double arg (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
39 extern OCTAVE_API double conj (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
40 extern OCTAVE_API double fix (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
41 extern OCTAVE_API double imag (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
42 extern OCTAVE_API double real (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
43 extern OCTAVE_API double xround (double x);
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
44 extern OCTAVE_API double xroundb (double x);
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
45 extern OCTAVE_API double signum (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
46 extern OCTAVE_API double xlog2 (double x);
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7636
diff changeset
47 extern OCTAVE_API Complex xlog2 (const Complex& x);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7636
diff changeset
48 extern OCTAVE_API double xlog2 (double x, int& exp);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7636
diff changeset
49 extern OCTAVE_API Complex xlog2 (const Complex& x, int& exp);
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
50 extern OCTAVE_API double xexp2 (double x);
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
51
7922
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
52 // These are used by the BOOL_OP macros in mx-op-defs.h.
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
53 inline bool xisnan (bool) { return false; }
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
54 inline bool xisnan (char) { return false; }
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
55
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
56 #if defined (HAVE_CMATH_ISNAN)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
57 inline bool xisnan (double x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
58 { return std::isnan (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
59 #else
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
60 extern OCTAVE_API bool xisnan (double x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
61 #endif
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
62 #if defined (HAVE_CMATH_ISFINITE)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
63 inline bool xfinite (double x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
64 { return std::isfinite (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
65 #else
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
66 extern OCTAVE_API bool xfinite (double x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
67 #endif
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
68 #if defined (HAVE_CMATH_ISINF)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
69 inline bool xisinf (double x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
70 { return std::isinf (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
71 #else
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
72 extern OCTAVE_API bool xisinf (double x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
73 #endif
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3156
diff changeset
74
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
75 extern OCTAVE_API bool octave_is_NA (double x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
76 extern OCTAVE_API bool octave_is_NaN_or_NA (double x) GCC_ATTR_DEPRECATED;
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3777
diff changeset
77
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
78 // Generic xmin, xmax definitions
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
79 template <class T>
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
80 inline T xmin (T x, T y)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
81 { return x <= y ? x : y; }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
82 template <class T>
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
83 inline T xmax (T x, T y)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
84 { return x >= y ? x : y; }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
85
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
86 // This form is favorable. GCC will translate (x <= y ? x : y) without a jump,
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
87 // hence the only conditional jump involved will be the first (xisnan), infrequent
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
88 // and hence friendly to branch prediction.
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
89 inline double xmin (double x, double y)
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
90 { return xisnan (y) ? x : (x <= y ? x : y);; }
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
91 inline double xmax (double x, double y)
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
92 { return xisnan (y) ? x : (x >= y ? x : y);; }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
93
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
94 extern OCTAVE_API Complex acos (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
95 extern OCTAVE_API Complex acosh (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
96 extern OCTAVE_API Complex asin (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
97 extern OCTAVE_API Complex asinh (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
98 extern OCTAVE_API Complex atan (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
99 extern OCTAVE_API Complex atanh (const Complex& x);
3777
b4f260ddd748 [project @ 2001-02-06 15:57:23 by jwe]
jwe
parents: 3776
diff changeset
100
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
101 extern OCTAVE_API Complex ceil (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
102 extern OCTAVE_API Complex fix (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
103 extern OCTAVE_API Complex floor (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
104 extern OCTAVE_API Complex xround (const Complex& x);
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
105 extern OCTAVE_API Complex xroundb (const Complex& x);
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
106 extern OCTAVE_API Complex signum (const Complex& x);
3776
7ed917c1ca60 [project @ 2001-02-06 05:21:32 by jwe]
jwe
parents: 3775
diff changeset
107
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
108 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
109 xisnan (const Complex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
110 { return (xisnan (real (x)) || xisnan (imag (x))); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
111 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
112 xfinite (const Complex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
113 { return (xfinite (real (x)) && xfinite (imag (x))); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
114 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
115 xisinf (const Complex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
116 { return (xisinf (real (x)) || xisinf (imag (x))); }
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3156
diff changeset
117
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
118 extern OCTAVE_API bool octave_is_NA (const Complex& x);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
119 extern OCTAVE_API bool octave_is_NaN_or_NA (const Complex& x);
4469
53ee020af847 [project @ 2003-07-26 03:45:10 by jwe]
jwe
parents: 4065
diff changeset
120
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
121 extern OCTAVE_API Complex xmin (const Complex& x, const Complex& y);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5904
diff changeset
122 extern OCTAVE_API Complex xmax (const Complex& x, const Complex& y);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3156
diff changeset
123
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
124 // Single Precision
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
125 inline float xtrunc (float x) { return gnulib::truncf (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
126 inline float xcopysign (float x, float y) { return copysignf (x, y); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
127 inline float xfloor (float x) { return floorf (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
128
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
129 extern OCTAVE_API float arg (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
130 extern OCTAVE_API float conj (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
131 extern OCTAVE_API float fix (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
132 extern OCTAVE_API float imag (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
133 extern OCTAVE_API float real (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
134 extern OCTAVE_API float xround (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
135 extern OCTAVE_API float xroundb (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
136 extern OCTAVE_API float signum (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
137 extern OCTAVE_API float xlog2 (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
138 extern OCTAVE_API FloatComplex xlog2 (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
139 extern OCTAVE_API float xlog2 (float x, int& exp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
140 extern OCTAVE_API FloatComplex xlog2 (const FloatComplex& x, int& exp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
141 extern OCTAVE_API float xexp2 (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
142
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
143 #if defined (HAVE_CMATH_ISNANF)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
144 inline bool xisnan (float x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
145 { return std::isnan (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
146 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
147 extern OCTAVE_API bool xisnan (float x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
148 #endif
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
149 #if defined (HAVE_CMATH_ISFINITEF)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
150 inline bool xfinite (float x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
151 { return std::isfinite (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
152 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
153 extern OCTAVE_API bool xfinite (float x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
154 #endif
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
155 #if defined (HAVE_CMATH_ISINFF)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
156 inline bool xisinf (float x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
157 { return std::isinf (x); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
158 #else
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
159 extern OCTAVE_API bool xisinf (float x);
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
160 #endif
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
161
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
162
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
163 extern OCTAVE_API bool octave_is_NA (float x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
164 extern OCTAVE_API bool octave_is_NaN_or_NA (float x) GCC_ATTR_DEPRECATED;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
165
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
166 inline float xmin (float x, float y)
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
167 { return xisnan (y) ? x : (x <= y ? x : y);; }
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
168 inline float xmax (float x, float y)
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
169 { return xisnan (y) ? x : (x >= y ? x : y);; }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
170
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
171 extern OCTAVE_API FloatComplex acos (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
172 extern OCTAVE_API FloatComplex acosh (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
173 extern OCTAVE_API FloatComplex asin (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
174 extern OCTAVE_API FloatComplex asinh (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
175 extern OCTAVE_API FloatComplex atan (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
176 extern OCTAVE_API FloatComplex atanh (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
177
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
178 extern OCTAVE_API FloatComplex ceil (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
179 extern OCTAVE_API FloatComplex fix (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
180 extern OCTAVE_API FloatComplex floor (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
181 extern OCTAVE_API FloatComplex xround (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
182 extern OCTAVE_API FloatComplex xroundb (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
183 extern OCTAVE_API FloatComplex signum (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
184
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
185 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
186 xisnan (const FloatComplex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
187 { return (xisnan (real (x)) || xisnan (imag (x))); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
188 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
189 xfinite (const FloatComplex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
190 { return (xfinite (real (x)) && xfinite (imag (x))); }
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
191 inline bool
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
192 xisinf (const FloatComplex& x)
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
193 { return (xisinf (real (x)) || xisinf (imag (x))); }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
194
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
195 extern OCTAVE_API bool octave_is_NA (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
196 extern OCTAVE_API bool octave_is_NaN_or_NA (const FloatComplex& x);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
197
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
198 extern OCTAVE_API FloatComplex xmin (const FloatComplex& x, const FloatComplex& y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
199 extern OCTAVE_API FloatComplex xmax (const FloatComplex& x, const FloatComplex& y);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
200
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
201 // These map reals to Complex.
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
202
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
203 extern OCTAVE_API Complex rc_acos (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
204 extern OCTAVE_API FloatComplex rc_acos (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
205 extern OCTAVE_API Complex rc_acosh (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
206 extern OCTAVE_API FloatComplex rc_acosh (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
207 extern OCTAVE_API Complex rc_asin (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
208 extern OCTAVE_API FloatComplex rc_asin (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
209 extern OCTAVE_API Complex rc_atanh (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
210 extern OCTAVE_API FloatComplex rc_atanh (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
211 extern OCTAVE_API Complex rc_log (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
212 extern OCTAVE_API FloatComplex rc_log (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
213 extern OCTAVE_API Complex rc_log2 (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
214 extern OCTAVE_API FloatComplex rc_log2 (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
215 extern OCTAVE_API Complex rc_log10 (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
216 extern OCTAVE_API FloatComplex rc_log10 (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
217 extern OCTAVE_API Complex rc_sqrt (double);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
218 extern OCTAVE_API FloatComplex rc_sqrt (float);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
219
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
220 // Some useful tests, that are commonly repeated.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
221 // Test for a finite integer.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
222 inline bool xisinteger (double x)
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
223 { return xfinite (x) && x == xround (x); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
224 inline bool xisinteger (float x)
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
225 { return xfinite (x) && x == xround (x); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
226
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
227 // Test for negative sign.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
228 extern OCTAVE_API bool xnegative_sign (double x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
229 extern OCTAVE_API bool xnegative_sign (float x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
230
11211
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
231 extern OCTAVE_API octave_idx_type NINTbig (double x);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
232 extern OCTAVE_API octave_idx_type NINTbig (float x);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
233
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
234 extern OCTAVE_API int NINT (double x);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
235 extern OCTAVE_API int NINT (float x);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
236
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
237 template <typename T>
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
238 OCTAVE_API
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
239 T
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
240 X_NINT (T x)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
241 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
242 return (xisinf (x) || xisnan (x)) ? x : xfloor (x + 0.5);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
243 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
244
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
245 inline OCTAVE_API double D_NINT (double x) { return X_NINT (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
246 inline OCTAVE_API float F_NINT (float x) { return X_NINT (x); }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
247
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
248 // Template functions can have either float or double arguments.
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
249
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
250 template <typename T>
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
251 OCTAVE_API
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
252 T
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
253 xmod (T x, T y)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
254 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
255 T retval;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
256
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
257 if (y == 0)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
258 retval = x;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
259 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
260 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
261 T q = x / y;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
262
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
263 T n = floor (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
264
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
265 if (X_NINT (y) != y)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
266 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
267 if (X_NINT (q) == q)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
268 n = q;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
269 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
270 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
271 if (x >= -1 && x <= 1)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
272 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
273 if (std::abs (q - X_NINT (q))
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
274 < std::numeric_limits<T>::epsilon ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
275 n = X_NINT (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
276 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
277 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
278 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
279 if (std::abs ((q - X_NINT (q))/ X_NINT (q))
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
280 < std::numeric_limits<T>::epsilon ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
281 n = D_NINT (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
282 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
283 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
284 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
285
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
286 retval = x - y * n;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
287 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
288
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
289 if (x != y && y != 0)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
290 retval = xcopysign (retval, y);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
291
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
292 return retval;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
293 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
294
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
295 template <typename T>
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
296 OCTAVE_API
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
297 T
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
298 xrem (T x, T y)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
299 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
300 T retval;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
301
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
302 if (y == 0)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
303 retval = x;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
304 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
305 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
306 T q = x / y;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
307
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
308 T n = xtrunc (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
309
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
310 if (X_NINT (y) != y)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
311 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
312 if (X_NINT (q) == q)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
313 n = q;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
314 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
315 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
316 if (x >= -1 && x <= 1)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
317 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
318 if (std::abs (q - X_NINT (q))
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
319 < std::numeric_limits<T>::epsilon ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
320 n = X_NINT (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
321 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
322 else
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
323 {
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
324 if (std::abs ((q - X_NINT (q))/ X_NINT (q))
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
325 < std::numeric_limits<T>::epsilon ())
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
326 n = X_NINT (q);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
327 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
328 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
329 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
330
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
331 retval = x - y * n;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
332 }
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
333
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
334 if (x != y && y != 0)
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
335 retval = xcopysign (retval, x);
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
336
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
337 return retval;
2554b4a0806e use templates for some lo-mappers functions
John W. Eaton <jwe@octave.org>
parents: 11209
diff changeset
338 }
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
339
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
340 #endif