37namespace triqs::utility {
58 std::complex<double> _x;
86 explicit operator std::complex<double>()
const {
return _x; }
93 explicit operator double()
const {
94 if (!_is_real)
TRIQS_RUNTIME_ERROR <<
"Logic error : the number is not real, it is complex";
140 x._x = std::conj(x._x);
155 return is_zero(x._x, tolerance);
169 out <<
'(' << x._x.real();
170 if (not std::signbit(x._x.imag())) out <<
'+';
171 out << x._x.imag() <<
"j)";
194 inline real_or_complex &operator OP(double y) { \
198 inline real_or_complex &operator OP(std::complex<double> const &y) { \
203 inline real_or_complex &operator OP(real_or_complex const &y) { \
205 _is_real &= y._is_real; \
217#define MAKE_OP(OP, OPC) \
218 inline real_or_complex operator OP(real_or_complex a, real_or_complex const &b) { \
222 inline real_or_complex operator OP(real_or_complex a, std::complex<double> const &b) { \
226 inline real_or_complex operator OP(real_or_complex a, double b) { \
230 inline real_or_complex operator OP(std::complex<double> const &a, real_or_complex b) { return a OP std::complex<double>(b); } \
231 inline real_or_complex operator OP(double a, real_or_complex b) { \
233 return a OP double(b); \
235 return a OP std::complex<double>(b); \
real_or_complex()
Default construct a real value initialized to zero.
bool operator!=(real_or_complex const &x) const
Not-equal-to operator compares the underlying complex values exactly.
friend real_or_complex conj(real_or_complex x)
Complex conjugate of a utility::real_or_complex value.
bool operator==(real_or_complex const &x) const
Equal-to operator compares the underlying complex values exactly.
real_or_complex(double x)
Construct a real value.
real_or_complex(std::complex< double > x)
Construct a complex value.
bool is_real() const
Whether the stored value is real.
friend double imag(real_or_complex const &x)
Imaginary part of a utility::real_or_complex value.
friend real_or_complex operator-(real_or_complex a)
Unary minus operator for a utility::real_or_complex value.
friend double real(real_or_complex const &x)
Real part of a utility::real_or_complex value.
friend std::ostream & operator<<(std::ostream &out, real_or_complex const &x)
Write a utility::real_or_complex value to an output stream.
real_or_complex()
Default construct a real value initialized to zero.
friend bool is_zero(real_or_complex const &x, double tolerance=100 *std::numeric_limits< double >::epsilon())
Zero check for a utility::real_or_complex value.
friend double abs(real_or_complex const &x)
Absolute value of a utility::real_or_complex value.
TRIQS exception hierarchy and related macros.
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
bool is_zero(I const &x)
Exact zero check for integral values.
Numeric helpers overloaded for various types.