Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
Loading...
Searching...
No Matches
complex_operators.hpp File Reference
#include <cmath>
#include <sstream>
#include <universal/math/complex/complex_impl.hpp>
#include <universal/math/complex/complex_native_real.hpp>

Namespaces

namespace  sw
 required std libraries
namespace  sw::universal

Functions

template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator+ (const complex< T > &c) noexcept
 Unary plus: returns a copy of the complex number.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator- (const complex< T > &c) noexcept
 Unary minus: returns the negation of the complex number.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator+ (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Addition of two complex numbers.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator- (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Subtraction of two complex numbers.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator* (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Multiplication of two complex numbers (a + bi) * (c + di) = (ac - bd) + (ad + bc)i.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator/ (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Division of two complex numbers (a + bi) / (c + di) = ((ac + bd) + (bc - ad)i) / (c^2 + d^2).
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator+ (const complex< T > &lhs, const T &rhs) noexcept
 Addition: complex + scalar.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator+ (const T &lhs, const complex< T > &rhs) noexcept
 Addition: scalar + complex.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator- (const complex< T > &lhs, const T &rhs) noexcept
 Subtraction: complex - scalar.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator- (const T &lhs, const complex< T > &rhs) noexcept
 Subtraction: scalar - complex.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator* (const complex< T > &lhs, const T &rhs) noexcept
 Multiplication: complex * scalar.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator* (const T &lhs, const complex< T > &rhs) noexcept
 Multiplication: scalar * complex.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator/ (const complex< T > &lhs, const T &rhs) noexcept
 Division: complex / scalar.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::operator/ (const T &lhs, const complex< T > &rhs) noexcept
 Division: scalar / complex.
template<ComplexCompatible T>
constexpr bool sw::universal::operator== (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Equality comparison.
template<ComplexCompatible T>
constexpr bool sw::universal::operator!= (const complex< T > &lhs, const complex< T > &rhs) noexcept
 Inequality comparison.
template<ComplexCompatible T>
constexpr bool sw::universal::operator== (const complex< T > &lhs, const T &rhs) noexcept
 Equality with scalar (imaginary part must be zero).
template<ComplexCompatible T>
constexpr bool sw::universal::operator== (const T &lhs, const complex< T > &rhs) noexcept
 Equality with scalar (imaginary part must be zero).
template<ComplexCompatible T>
constexpr bool sw::universal::operator!= (const complex< T > &lhs, const T &rhs) noexcept
 Inequality with scalar.
template<ComplexCompatible T>
constexpr bool sw::universal::operator!= (const T &lhs, const complex< T > &rhs) noexcept
 Inequality with scalar.
template<ComplexCompatible T>
constexpr T sw::universal::real (const complex< T > &c) noexcept
 Extract the real component.
template<ComplexCompatible T>
constexpr T sw::universal::imag (const complex< T > &c) noexcept
 Extract the imaginary component.
template<ComplexCompatible T>
constexpr complex< T > sw::universal::conj (const complex< T > &c) noexcept
 Complex conjugate: conj(a + bi) = a - bi.
template<ComplexCompatible T>
constexpr T sw::universal::norm (const complex< T > &c) noexcept
 Squared magnitude (norm): |z|^2 = a^2 + b^2.
template<ComplexCompatible T>
T sw::universal::abs (const complex< T > &c)
 Absolute value (magnitude): |z| = sqrt(a^2 + b^2) A high-precision T (is_high_precision) computes it in T, scaled like hypot so that a^2 cannot overflow or underflow; any other T goes through double.
template<ComplexCompatible T>
T sw::universal::arg (const complex< T > &c)
 Phase angle (argument): arg(z) = atan2(b, a), in T for a high-precision T.
template<ComplexCompatible T>
complex< T > sw::universal::polar (const T &rho, const T &theta=T{})
 Construct complex from polar coordinates: polar(rho, theta) = rho * (cos(theta) + i*sin(theta)).
template<ComplexCompatible T>
complex< T > sw::universal::proj (const complex< T > &c)
 Project onto the Riemann sphere.
template<ComplexCompatible T>
bool sw::universal::isnan (const complex< T > &c)
 Check if any component is NaN A high-precision T is classified by its own isnan/isinf: its range can exceed double's.
template<ComplexCompatible T>
bool sw::universal::isinf (const complex< T > &c)
 Check if any component is infinite.
template<ComplexCompatible T>
bool sw::universal::isfinite (const complex< T > &c)
 Check if both components are finite.
template<ComplexCompatible T>
bool sw::universal::isnormal (const complex< T > &c)
 Check if both components are normal (not zero, subnormal, infinite, or NaN).
template<ComplexCompatible T>
std::ostream & sw::universal::operator<< (std::ostream &os, const complex< T > &c)
 Output stream operator: formats as (real,imag).
template<ComplexCompatible T>
std::istream & sw::universal::operator>> (std::istream &is, complex< T > &c)
 Input stream operator: expects format (real,imag).