annotate liboctave/util/oct-cmplx.h @ 20830:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents 31e3799b9e27
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
1 /*
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
2
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19832
diff changeset
3 Copyright (C) 1995-2015 John W. Eaton
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
4 Copyright (C) 2009 VZLU Prague, a.s.
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
5
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
7
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 option) any later version.
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
12
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
16 for more details.
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
17
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
20 <http://www.gnu.org/licenses/>.
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
21
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
22 */
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
23
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
24 #if !defined (octave_oct_cmplx_h)
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
25 #define octave_oct_cmplx_h 1
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
26
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
27 #include <complex>
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
28
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
29 typedef std::complex<double> Complex;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
30 typedef std::complex<float> FloatComplex;
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
31
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
32 // For complex-complex and complex-real comparisons, we use the following
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
33 // ordering: compare absolute values first; if they match, compare phase angles.
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
34 // This is partially inconsistent with M*b, which compares complex numbers only
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
35 // by their real parts; OTOH, it uses the same definition for max/min and sort.
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
36 // The abs/arg comparison is definitely more useful (the other one is emulated
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
37 // rather trivially), so let's be consistent and use that all over.
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
38
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
39 // The standard C library function arg() returns [-pi,pi], which creates a
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
40 // non-unique representation for numbers along the negative real axis branch
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
41 // cut. Change this to principal value (-pi,pi] by mapping -pi to pi.
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
42
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
43 #define DEF_COMPLEXR_COMP(OP, OPS) \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
44 template <class T> \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
45 inline bool operator OP (const std::complex<T>& a, const std::complex<T>& b) \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
46 { \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
47 FLOAT_TRUNCATE const T ax = std::abs (a); \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
48 FLOAT_TRUNCATE const T bx = std::abs (b); \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
49 if (ax == bx) \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
50 { \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
51 FLOAT_TRUNCATE const T ay = std::arg (a); \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
52 FLOAT_TRUNCATE const T by = std::arg (b); \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
53 if (ay == static_cast<T> (-M_PI)) \
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
54 { \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
55 if (by != static_cast<T> (-M_PI)) \
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
56 return static_cast<T> (M_PI) OP by; \
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
57 } \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
58 else if (by == static_cast<T> (-M_PI)) \
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
59 { \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
60 return ay OP static_cast<T> (M_PI); \
19832
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 18084
diff changeset
61 } \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
62 return ay OP by; \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
63 } \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
64 else \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
65 return ax OPS bx; \
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
66 } \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
67 template <class T> \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
68 inline bool operator OP (const std::complex<T>& a, T b) \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
69 { \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
70 FLOAT_TRUNCATE const T ax = std::abs (a); \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
71 FLOAT_TRUNCATE const T bx = std::abs (b); \
9667
641a788c82a4 fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9603
diff changeset
72 if (ax == bx) \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
73 { \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
74 FLOAT_TRUNCATE const T ay = std::arg (a); \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
75 if (ay == static_cast<T> (-M_PI)) \
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
76 return static_cast<T> (M_PI) OP 0; \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
77 return ay OP 0; \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
78 } \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
79 else \
9667
641a788c82a4 fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9603
diff changeset
80 return ax OPS bx; \
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
81 } \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
82 template <class T> \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
83 inline bool operator OP (T a, const std::complex<T>& b) \
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
84 { \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
85 FLOAT_TRUNCATE const T ax = std::abs (a); \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
86 FLOAT_TRUNCATE const T bx = std::abs (b); \
9667
641a788c82a4 fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9603
diff changeset
87 if (ax == bx) \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
88 { \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
89 FLOAT_TRUNCATE const T by = std::arg (b); \
20132
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
90 if (by == static_cast<T> (-M_PI)) \
31e3799b9e27 Map -pi to pi for principal argument in complex operators with float values (bug #43313)
Rik <rik@octave.org>
parents: 19898
diff changeset
91 return 0 OP static_cast<T> (M_PI); \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
92 return 0 OP by; \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
93 } \
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
94 else \
9667
641a788c82a4 fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9603
diff changeset
95 return ax OPS bx; \
9603
8bea4e89326f implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents: 9594
diff changeset
96 }
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
97
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
98 DEF_COMPLEXR_COMP (>, >)
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
99 DEF_COMPLEXR_COMP (<, <)
9594
01004c3cde2c fix non-strict complex comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
100 DEF_COMPLEXR_COMP (<=, <)
01004c3cde2c fix non-strict complex comparisons
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
101 DEF_COMPLEXR_COMP (>=, >)
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
102
1648
65ef5beea500 [project @ 1995-12-20 06:43:29 by jwe]
jwe
parents:
diff changeset
103 #endif