TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::utility::real_or_complex

#include <triqs/utility/real_or_complex.hpp>

Detailed Description

Type that can represent either a real or a complex number.

Internally stores a std::complex<double> and a bool flag indicating whether the imaginary part is known to be zero.

Arithmetic operations (+, -, *, /) and compound assignment operations (+=, -=, *=, /=) are provided for all combinations of real_or_complex, std::complex<double> and double operands. The result is real if and only if both operands are real.

Once the value is considered complex, conversion back to real throws.

Definition at line 56 of file real_or_complex.hpp.

Public Member Functions

 real_or_complex ()
 Default construct a real value initialized to zero.
 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.
 operator double () const
 Explicit conversion to double.
 operator std::complex< double > () const
 Explicit conversion to std::complex<double>.
bool operator!= (real_or_complex const &x) const
 Not-equal-to operator compares the underlying complex values exactly.
bool operator== (real_or_complex const &x) const
 Equal-to operator compares the underlying complex values exactly.

Friends

double abs (real_or_complex const &x)
 Absolute value of a utility::real_or_complex value.
real_or_complex conj (real_or_complex x)
 Complex conjugate of a utility::real_or_complex value.
double imag (real_or_complex const &x)
 Imaginary part of a utility::real_or_complex value.
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.
real_or_complex operator- (real_or_complex a)
 Unary minus operator for a utility::real_or_complex value.
std::ostream & operator<< (std::ostream &out, real_or_complex const &x)
 Write a utility::real_or_complex value to an output stream.
double real (real_or_complex const &x)
 Real part of a utility::real_or_complex value.

Constructor & Destructor Documentation

◆ real_or_complex() [1/2]

triqs::utility::real_or_complex::real_or_complex ( double x)
inline

Construct a real value.

Parameters
xReal value to store.

Definition at line 68 of file real_or_complex.hpp.

◆ real_or_complex() [2/2]

triqs::utility::real_or_complex::real_or_complex ( std::complex< double > x)
inline

Construct a complex value.

Parameters
xComplex value to store.

Definition at line 74 of file real_or_complex.hpp.

Member Function Documentation

◆ is_real()

bool triqs::utility::real_or_complex::is_real ( ) const
inline

Whether the stored value is real.

Returns
True if the stored value is real, false if it is complex.

Definition at line 80 of file real_or_complex.hpp.

◆ operator double()

triqs::utility::real_or_complex::operator double ( ) const
inlineexplicit

Explicit conversion to double.

It throws a triqs::runtime_error if the stored value is complex.

Returns
The real part of the stored value.

Definition at line 93 of file real_or_complex.hpp.

◆ operator std::complex< double >()

triqs::utility::real_or_complex::operator std::complex< double > ( ) const
inlineexplicit

Explicit conversion to std::complex<double>.

Returns
The stored value as a complex number.

Definition at line 86 of file real_or_complex.hpp.

◆ operator!=()

bool triqs::utility::real_or_complex::operator!= ( real_or_complex const & x) const
inline

Not-equal-to operator compares the underlying complex values exactly.

Parameters
xValue to compare against.
Returns
True if the underlying complex values differ, false otherwise.

Definition at line 190 of file real_or_complex.hpp.

◆ operator==()

bool triqs::utility::real_or_complex::operator== ( real_or_complex const & x) const
inline

Equal-to operator compares the underlying complex values exactly.

Parameters
xValue to compare against.
Returns
True if the underlying complex values are exactly equal, false otherwise.

Definition at line 182 of file real_or_complex.hpp.

◆ abs

double abs ( real_or_complex const & x)
friend

Absolute value of a utility::real_or_complex value.

Parameters
xValue to inspect.
Returns
The absolute value.

Definition at line 131 of file real_or_complex.hpp.

◆ conj

real_or_complex conj ( real_or_complex x)
friend

Complex conjugate of a utility::real_or_complex value.

Parameters
xValue to conjugate.
Returns
The complex conjugate.

Definition at line 139 of file real_or_complex.hpp.

◆ imag

double imag ( real_or_complex const & x)
friend

Imaginary part of a utility::real_or_complex value.

Parameters
xValue to inspect.
Returns
The imaginary part.

Definition at line 123 of file real_or_complex.hpp.

◆ is_zero

bool is_zero ( real_or_complex const & x,
double tolerance = 100 * std::numeric_limits<double>::epsilon() )
friend

Zero check for a utility::real_or_complex value.

Parameters
xValue to test.
toleranceAbsolute tolerance \( \epsilon \).
Returns
True if the absolute values of real and imaginary parts are both less than \( \epsilon \), false otherwise.

Definition at line 152 of file real_or_complex.hpp.

◆ operator-

real_or_complex operator- ( real_or_complex a)
friend

Unary minus operator for a utility::real_or_complex value.

Parameters
aValue to negate.
Returns
Negated value.

Definition at line 104 of file real_or_complex.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
real_or_complex const & x )
friend

Write a utility::real_or_complex value to an output stream.

Parameters
outOutput stream to write to.
xValue to write.
Returns
Reference to the output stream.

Definition at line 165 of file real_or_complex.hpp.

◆ real

double real ( real_or_complex const & x)
friend

Real part of a utility::real_or_complex value.

Parameters
xValue to inspect.
Returns
The real part.

Definition at line 115 of file real_or_complex.hpp.


The documentation for this class was generated from the following file: