GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
util
oct-cmplx.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1995-2013 John W. Eaton
4
Copyright (C) 2009 VZLU Prague, a.s.
5
6
This file is part of Octave.
7
8
Octave is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 3 of the License, or (at your
11
option) any later version.
12
13
Octave is distributed in the hope that it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Octave; see the file COPYING. If not, see
20
<http://www.gnu.org/licenses/>.
21
22
*/
23
24
#if !defined (octave_oct_cmplx_h)
25
#define octave_oct_cmplx_h 1
26
27
#include <complex>
28
29
typedef
std::complex<double>
Complex
;
30
typedef
std::complex<float>
FloatComplex
;
31
32
// For complex-complex and complex-real comparisons, we use the following
33
// ordering: compare absolute values first; if they match, compare phase angles.
34
// This is partially inconsistent with M*b, which compares complex numbers only
35
// by their real parts; OTOH, it uses the same definition for max/min and sort.
36
// The abs/arg comparison is definitely more useful (the other one is emulated
37
// rather trivially), so let's be consistent and use that all over.
38
39
#define DEF_COMPLEXR_COMP(OP, OPS) \
40
template <class T> \
41
inline bool operator OP (const std::complex<T>& a, const std::complex<T>& b) \
42
{ \
43
FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \
44
if (ax == bx) \
45
{ \
46
FLOAT_TRUNCATE const T ay = std::arg (a), by = std::arg (b); \
47
return ay OP by; \
48
} \
49
else \
50
return ax OPS bx; \
51
} \
52
template <class T> \
53
inline bool operator OP (const std::complex<T>& a, T b) \
54
{ \
55
FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \
56
if (ax == bx) \
57
{ \
58
FLOAT_TRUNCATE const T ay = std::arg (a); \
59
return ay OP 0; \
60
} \
61
else \
62
return ax OPS bx; \
63
} \
64
template <class T> \
65
inline bool operator OP (T a, const std::complex<T>& b) \
66
{ \
67
FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \
68
if (ax == bx) \
69
{ \
70
FLOAT_TRUNCATE const T by = std::arg (b); \
71
return 0 OP by; \
72
} \
73
else \
74
return ax OPS bx; \
75
}
76
77
DEF_COMPLEXR_COMP
(>, >)
78
DEF_COMPLEXR_COMP
(<, <)
79
DEF_COMPLEXR_COMP
(<=, <)
80
DEF_COMPLEXR_COMP
(>=, >)
81
82
#endif
Generated on Mon Dec 30 2013 03:04:54 for GNU Octave by
1.8.1.2