Complex Number Listing#

namespace librapid

Functions

template<typename T>
auto operator-(const Complex<T> &other) -> Complex<T>#

Negate a complex number.

Template Parameters

T – Scalar type of the complex number

Parameters

otherComplex number to negate

Returns

Negated complex number

template<typename L, typename R>
auto operator+(const Complex<L> &left, const Complex<R> &right)#

Add two complex numbers.

Add two complex numbers together, returning the result

Template Parameters
  • L – Scalar type of LHS

  • R – Scalar type of RHS

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

Sum of LHS and RHS

template<typename T, typename R>
auto operator+(const Complex<T> &left, const R &right)#

Add a complex number and a scalar.

Add a real number to the real component of a complex number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

Sum of LHS and RHS

template<typename R, typename T>
auto operator+(const R &left, const Complex<T> &right)#

Add a scalar to a complex number.

Add a real number to the real component of a complex number, returning the result

Template Parameters
  • R – Type of the real number

  • T – Scalar type of the complex number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

Sum of LHS and RHS

template<typename L, typename R>
auto operator-(const Complex<L> &left, const Complex<R> &right)#

Subtract a complex number from another complex number.

Subtract the real and imaginary components of the RHS complex number from the corresponding components of the LHS complex number, returning the result

Template Parameters
  • L – Scalar type of the LHS complex number

  • R – Scalar type of the RHS complex number

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

Difference of LHS and RHS

template<typename T, typename R>
auto operator-(const Complex<T> &left, const R &right)#

Subtract a scalar from a complex number.

Subtract a real number from the real component of a complex number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

Difference of LHS and RHS

template<typename T, typename R>
auto operator-(const R &left, const Complex<T> &right)#

Subtract a complex number from a scalar.

Subtract the real and imaginary components of the RHS complex number from a real number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

Difference of LHS and RHS

template<typename L, typename R>
auto operator*(const Complex<L> &left, const Complex<R> &right)#

Multiply two complex numbers.

Multiply the LHS and RHS complex numbers, returning the result

Template Parameters
  • L – Scalar type of the LHS complex number

  • R – Scalar type of the RHS complex number

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

Product of LHS and RHS

template<typename T, typename R>
auto operator*(const Complex<T> &left, const R &right)#

Multiply a complex number by a scalar.

Multiply the real and imaginary components of a complex number by a real number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

Product of LHS and RHS

template<typename T, typename R>
auto operator*(const R &left, const Complex<T> &right)#

Multiply a scalar by a complex number.

Multiply a real number by the real and imaginary components of a complex number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

Product of LHS and RHS

template<typename L, typename R>
auto operator/(const Complex<L> &left, const Complex<R> &right)#

Divide two complex numbers.

Divide the LHS complex number by the RHS complex number, returning the result

Template Parameters
  • L – Scalar type of the LHS complex number

  • R – Scalar type of the RHS complex number

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

Quotient of LHS and RHS

template<typename T, typename R>
auto operator/(const Complex<T> &left, const R &right)#

Divide a complex number by a scalar.

Divide the real and imaginary components of a complex number by a real number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

Quotient of LHS and RHS

template<typename T, typename R>
auto operator/(const R &left, const Complex<T> &right)#

Divide a scalar by a complex number.

Divide a real number by the real and imaginary components of a complex number, returning the result

Template Parameters
  • T – Scalar type of the complex number

  • R – Type of the real number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

Quotient of LHS and RHS

template<typename L, typename R>
constexpr bool operator==(const Complex<L> &left, const Complex<R> &right)

Equality comparison of two complex numbers.

Template Parameters
  • L – Scalar type of LHS complex number

  • R – Scalar type of RHS complex number

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

true if equal, false otherwise

template<typename T>
constexpr bool operator==(const Complex<T> &left, T &right)

Equality comparison of complex number and scalar.

Compares the real component of the complex number to the scalar, and the imaginary component to zero. Returns true if and only if both comparisons are true.

Template Parameters

T – Scalar type of complex number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

true if equal, false otherwise

template<typename T>
constexpr bool operator==(const T &left, const Complex<T> &right)

Equality comparison of scalar and complex number.

Compares the real component of the complex number to the scalar, and the imaginary component to zero. Returns true if and only if both comparisons are true.

Template Parameters

T – Scalar type of complex number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

true if equal, false otherwise

template<typename T>
constexpr bool operator!=(const Complex<T> &left, const Complex<T> &right)

Inequality comparison of two complex numbers.

Template Parameters

T – Scalar type of complex number

Parameters
  • left – LHS complex number

  • right – RHS complex number

Returns

true if equal, false otherwise

template<typename T>
constexpr bool operator!=(const Complex<T> &left, T &right)

Inequality comparison of complex number and scalar.

Template Parameters

T – Scalar type of complex number

Parameters
  • left – LHS complex number

  • right – RHS scalar

Returns

true if equal, false otherwise

template<typename T>
constexpr bool operator!=(const T &left, const Complex<T> &right)

Inequality comparison of scalar and complex number.

Template Parameters

T – Scalar type of complex number

Parameters
  • left – LHS scalar

  • right – RHS complex number

Returns

true if equal, false otherwise

template<typename T>
T real(const Complex<T> &val)

Return \( \mathrm{Re}(z) \).

Template Parameters

T – Scalar type of the complex number

Parameters

valComplex number

Returns

Real component of the complex number

template<typename T>
T imag(const Complex<T> &val)

Return \( \mathrm{Im}(z) \).

Template Parameters

T – Scalar type of the complex number

Parameters

valComplex number

Returns

Imaginary component of the complex number

template<typename T>
Complex<T> sqrt(const Complex<T> &val)

Return \( \sqrt{z} \).

Template Parameters

T – Scalar type of the complex number

Parameters

valComplex number

Returns

Square root of the complex number

template<typename T>
T abs(const Complex<T> &val)

Return \( \sqrt{\mathrm{Re}(z)^2 + \mathrm{Im}(z)^2} \).

Template Parameters

T – Scalar type of the complex number

Parameters

valComplex number

Returns

Absolute value of the complex number

template<typename T>
Complex<T> conj(const Complex<T> &val)

Returns \(z^{*}\).

Template Parameters

T – Scalar type of the complex number

Parameters

valComplex number

Returns

Complex conjugate of the complex number

template<typename T>
Complex<T> acos(const Complex<T> &other)

Compute the complex arc cosine of a complex number.

This function computes the complex arc cosine of the input complex number, \(\text{acos}(z)\)

The algorithm handles NaN and infinity values, and avoids overflow.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex arc cosine of the input complex number

template<typename T>
Complex<T> acosh(const Complex<T> &other)

Compute the complex hyperbolic arc cosine of a complex number.

This function computes the complex area hyperbolic cosine of the input complex number, \( \text{acosh}(z) \)

The algorithm handles NaN and infinity values, and avoids overflow.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex area hyperbolic cosine of the input complex number

template<typename T>
Complex<T> asinh(const Complex<T> &other)

Compute the complex arc hyperbolic sine of a complex number.

This function computes the complex arc hyperbolic sine of the input complex number, \( \text{asinh}(z) \)

The algorithm handles NaN and infinity values, and avoids overflow.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex arc hyperbolic sine of the input complex number

template<typename T>
Complex<T> asin(const Complex<T> &other)

Compute the complex arc sine of a complex number.

This function computes the complex arc sine of the input complex number, \( \text{asin}(z) \)

It calculates the complex arc sine by using the complex hyperbolic sine function.

See also

asinh

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex arc sine of the input complex number

template<typename T>
Complex<T> atanh(const Complex<T> &other)

Compute the complex arc hyperbolic tangent of a complex number.

This function computes the complex arc hyperbolic tangent of the input complex number, \( \text{atanh}(z) \)

This function performs error checking and supports NaNs and Infs.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex arc hyperbolic tangent of the input complex number

template<typename T>
Complex<T> atan(const Complex<T> &other)

Compute the complex arc tangent of a complex number.

This function computes the complex arc tangent of the input complex number, \( \text{atan}(z) \)

The algorithm handles NaN and infinity values, and avoids overflow.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex arc tangent of the input complex number

template<typename T>
Complex<T> cosh(const Complex<T> &other)

Compute the complex hyperbolic cosine of a complex number.

This function computes the complex hyperbolic cosine of the input complex number, \( \text{cosh}(z) \)

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex hyperbolic cosine of the input complex number

template<typename T>
Complex<T> polarPositiveNanInfZeroRho(const T &rho, const T &theta)
template<typename T>
Complex<T> exp(const Complex<T> &other)

Compute the complex exponential of a complex number.

This function computes the complex exponential of the input complex number, \( e^z \)

The algorithm handles NaN and infinity values.

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex exponential of the input complex number

template<typename T>
Complex<T> exp2(const Complex<T> &other)

Compute the complex exponential base 2 of a complex number.

See also

exp

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex exponential base 2 of the input complex number

template<typename T>
Complex<T> exp10(const Complex<T> &other)

Compute the complex exponential base 10 of a complex number.

See also

exp

Template Parameters

T – Scalar type of the complex number

Parameters

other – Input complex number

Returns

Complex exponential base 10 of the input complex number

template<typename T>
T _fabs(const Complex<T> &other, int64_t *exp)
template<typename T>
T _logAbs(const Complex<T> &other) noexcept
template<>
mpfr _logAbs(const Complex<mpfr> &other) noexcept
template<>
float _logAbs(const Complex<float> &other) noexcept
template<typename T>
Complex<T> log(const Complex<T> &other)

Calculates the natural logarithm of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

Natural logarithm of the complex number

template<typename T, typename B>
Complex<T> log(const Complex<T> &other, const Complex<T> &base)

Calculates the logarithm of a complex number with a complex base.

\( \log_{\mathrm{base}}(z) = \log(z) / \log(\mathrm{base}) \)

See also

log

Template Parameters
  • T – Scalar type

  • B – Base type

Parameters
  • otherComplex number

  • base – Base of the logarithm

Returns

Logarithm of the complex number with the given base

template<typename T, typename B>
Complex<T> log(const Complex<T> &other, const B &base)

Calculates the logarithm of a complex number with a real base.

\( \log_{\mathrm{base}}(z) = \log(z) / \log(\mathrm{base}) \)

See also

log

Template Parameters
  • T – Scalar type of the complex number

  • B – Scalar type of the base

Parameters
  • otherComplex number

  • base – Base of the logarithm (real)

Returns

Logarithm of the complex number with the given base

template<typename T>
Complex<T> _pow(const T &left, const T &right)
template<typename T, typename V, typename std::enable_if_t<typetraits::TypeInfo<V>::type == detail::LibRapidType::Scalar, int> = 0>
Complex<T> pow(const Complex<T> &left, const V &right)

Calculate \( \text{left}^{\text{right}} \) for a complex-valued left-hand side.

Template Parameters
  • T – Value type for the left-hand side

  • V – Value type for the right-hand side

Parameters
  • leftComplex base

  • right – Real exponent

Returns

\( \text{left}^{\text{right}} \)

template<typename T, typename V, typename std::enable_if_t<typetraits::TypeInfo<V>::type == detail::LibRapidType::Scalar, int> = 0>
Complex<T> pow(const V &left, const Complex<T> &right)

Calculate \( \text{left}^{\text{right}} \) for a complex-valued right-hand side.

Template Parameters
  • T – Value type for the left-hand side

  • V – Value type for the right-hand side

Parameters
  • left – Real base

  • rightComplex exponent

Returns

\( \text{left}^{\text{right}} \)

template<typename T>
Complex<T> pow(const Complex<T> &left, const Complex<T> &right)

Calculate \( \text{left}^{\text{right}} \) for complex numbers.

Template Parameters

TComplex number component type

Parameters
Returns

\( \text{left}^{\text{right}} \)

template<typename T>
Complex<T> sinh(const Complex<T> &other)

Calculate the hyperbolic sine of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \sinh(z) \)

template<typename T>
Complex<T> tanh(const Complex<T> &other)

Calculate the hyperbolic tangent of a complex number.

This function supports propagation of NaNs and Infs.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \tanh(z) \)

template<typename T>
T arg(const Complex<T> &other)

Return the phase angle of a complex value as a real.

This function calls \( \text{atan2}(\text{imag}(z), \text{real}(z)) \).

See also

atan2

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \arg(z) \)

template<typename T>
Complex<T> proj(const Complex<T> &other)

Project a complex number onto the Riemann sphere.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \text{proj}(z) \)

template<typename T>
Complex<T> cos(const Complex<T> &other)

Calculate the cosine of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \cos(z) \)

template<typename T>
Complex<T> csc(const Complex<T> &other)

Calculate the cosecant of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \csc(z) \)

template<typename T>
Complex<T> sec(const Complex<T> &other)

Calculate the secant of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \sec(z) \)

template<typename T>
Complex<T> cot(const Complex<T> &other)

Calculate the cotangent of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \cot(z) \)

template<typename T>
Complex<T> acsc(const Complex<T> &other)

Calculate the arc cosecant of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \operatorname{arccsc}(z) \)

template<typename T>
Complex<T> asec(const Complex<T> &other)

Calculate the arc secant of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \operatorname{arcsec}(z) \)

template<typename T>
Complex<T> acot(const Complex<T> &other)

Calculate the arc cotangent of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \operatorname{arccot}(z) \)

template<typename T>
Complex<T> log2(const Complex<T> &other)

Calculate the logarithm base 2 of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \log_2(z) \)

template<typename T>
Complex<T> log10(const Complex<T> &other)

Calculate the logarithm base 10 of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \log_{10}(z) \)

template<typename T>
T norm(const Complex<T> &other)

Calculate the magnitude squared of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( |z|^2 \)

template<typename T>
Complex<T> polar(const T &rho, const T &theta)

Return a complex number from polar coordinates.

Given a radius, rho, and an angle, theta, this function returns the complex number \( \rho e^{i\theta} \).

The function returns NaN, infinity or zero based on the input values of rho.

Template Parameters

T – Scalar type of the complex number

Parameters
  • rho – Radius of the polar coordinate system

  • theta – Angle of the polar coordinate system

Returns

Complex number in polar form.

template<typename T>
Complex<T> sin(const Complex<T> &other)

Compute the sine of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \sin(z) \)

template<typename T>
Complex<T> tan(const Complex<T> &other)

Compute the tangent of a complex number.

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( \tan(z) \)

template<typename T>
Complex<T> floor(const Complex<T> &other)

Round the real and imaginary parts of a complex number towards \( -\infty \).

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\( (\lfloor\operatorname{real}(z)\rfloor,\lfloor\operatorname{imag}(z)\rfloor )\)

template<typename T>
Complex<T> ceil(const Complex<T> &other)

Round the real and imaginary parts of a complex number towards \( +\infty \).

Template Parameters

T – Scalar type

Parameters

otherComplex number

Returns

\((\lceil\operatorname{real}(z)\rceil,\lceil\operatorname{imag}(z)\rceil )\)

template<typename T>
auto random(const Complex<T> &min, const Complex<T> &max, uint64_t seed = -1) -> Complex<T>

Generate a random complex number between two given complex numbers.

This function generates a random complex number in the range [min, max], where min and max are given as input. The function uses a default seed if none is provided.

Template Parameters

T – Scalar type of the complex number

Parameters
  • min – Minimum complex number

  • max – Maximum complex number

  • seed – Seed for the random number generator

Returns

Random complex number between min and max

template<typename T = double>
class Complex
#include <complex.hpp>

A class representing a complex number of the form \(a + bi\), where \(a\) and \(b\) are real numbers.

This class represents a complex number of the form \(a + bi\), where \(a\) and \(b\) are real numbers. The class is templated, allowing the user to specify the type of the real and imaginary components. The default type is double.

Template Parameters

T – The type of the real and imaginary components

Public Types

using Scalar = typename typetraits::TypeInfo<T>::Scalar

Public Functions

inline Complex()

Default constructor.

Create a new complex number. Both the real and imaginary components are set to zero

template<typename R>
inline explicit Complex(const R &realVal)

Construct a complex number from a real number.

Create a complex number, setting only the real component. The imaginary component is initialized to zero

Template Parameters

R – The type of the real component

Parameters

realVal – The real component

template<typename R, typename I>
inline Complex(const R &realVal, const I &imagVal)

Construct a complex number from real and imaginary components.

Create a new complex number where both the real and imaginary parts are set from the passed parameters

Template Parameters
  • R – The type of the real component

  • I – The type of the imaginary component

Parameters
  • realVal – The real component

  • imagVal – The imaginary component

inline Complex(const Complex<T> &other)

Complex number copy constructor.

Parameters

other – The complex number to copy

inline Complex(Complex<T> &&other) noexcept

Complex number move constructor.

Parameters

other – The complex number to move

template<typename Other>
inline Complex(const Complex<Other> &other)

Construct a complex number from another complex number with a different type.

Template Parameters

Other – Type of the components of the other complex number

Parameters

other – The complex number to copy

inline explicit Complex(const std::complex<T> &other)

Construct a complex number from a std::complex.

Parameters

other – The std::complex value to copy

inline auto operator=(const Complex<T> &other) -> Complex<T>&

Complex number assignment operator.

Parameters

other – The value to assign

Returns

*this

inline void real(const T &val)

Assign to the real component.

Set the real component of this complex number to val

Parameters

val – The value to assign

inline void imag(const T &val)

Assign to the imaginary component.

Set the imaginary component of this complex number to val

Parameters

val – The value to assign

inline auto real() const -> const T&

Access the real component.

Returns a const reference to the real component of this complex number

Returns

Real component

inline auto imag() const -> const T&

Access the imaginary component.

Returns a const reference to the imaginary component of this complex number

Returns

Imaginary component

inline auto real() -> T&

Access the real component.

Returns a reference to the real component of this complex number. Since this is a reference type, it can be assigned to

Returns

Real component

inline auto imag() -> T&

Access the imaginary component.

Returns a reference to the imaginary component of this complex number. Since this is a reference type, it can be assigned to

Returns

imaginary component

inline auto operator=(const T &other) -> Complex&

Complex number assigment operator.

Set the real component of this complex number to other, and the imaginary component to 0

Parameters

other

Returns

*this

template<typename Other>
inline auto operator=(const Complex<Other> &other) -> Complex&

Complex number assigment operator.

Assign another complex number to this one, copying the real and imaginary components

Template Parameters

Other – The type of the other complex number

Parameters

otherComplex number to assign

Returns

*this

inline auto operator+=(const T &other) -> Complex&

Inplace addition.

Add a scalar value to the real component of this imaginary number

Parameters

other – Scalar value to add

Returns

*this

inline auto operator-=(const T &other) -> Complex&

Inplace subtraction.

Subtract a scalar value from the real component of this imaginary number

Parameters

other – Scalar value to subtract

Returns

*this

inline auto operator*=(const T &other) -> Complex&

Inplace multiplication.

Multiply both the real and imaginary components of this complex number by a scalar

Parameters

other – Scalar value to multiply by

Returns

*this

inline auto operator/=(const T &other) -> Complex&

Inplace division.

Divide both the real and imaginary components of this complex number by a scalar

Parameters

other – Scalar value to divide by

Returns

*this

inline auto operator+=(const Complex &other) -> Complex&

Inplace addition.

Add a complex number to this one

Parameters

otherComplex number to add

Returns

*this

inline auto operator-=(const Complex &other) -> Complex&

Inplace subtraction.

Subtract a complex number from this one

Parameters

otherComplex number to subtract

Returns

*this

inline auto operator*=(const Complex &other) -> Complex&

Inplace multiplication.

Multiply this complex number by another one

Parameters

otherComplex number to multiply by

Returns

*this

inline auto operator/=(const Complex &other) -> Complex&

Inplace division.

Divide this complex number by another one

Parameters

otherComplex number to divide by

Returns

*this

template<typename To>
inline explicit operator To() const

Cast to scalar types.

Cast this complex number to a scalar type. This will extract only the real component.

Template Parameters

To – Type to cast to

Returns

Scalar

template<typename To>
inline explicit operator Complex<To>() const

Cast to a complex number with a different scalar type.

Cast the real and imaginary components of this complex number to a different type and return the result as a new complex number

Template Parameters

To – Scalar type to cast to

Returns

Complex number

template<typename T_, typename Char, typename Ctx>
inline void str(const fmt::formatter<T_, Char> &format, Ctx &ctx) const

Public Static Functions

static inline constexpr auto size() -> size_t

Protected Functions

template<typename Other>
inline void _add(const Complex<Other> &other)

Add a complex number to this one.

Template Parameters

Other – Scalar type of the other complex number

Parameters

other – Other complex number

template<typename Other>
inline void _sub(const Complex<Other> &other)

Subtract a complex number from this one.

Template Parameters

Other – Scalar type of the other complex number

Parameters

other – Other complex number

template<typename Other>
inline void _mul(const Complex<Other> &other)

Multiply this complex number by another one.

Template Parameters

Other – Scalar type of the other complex number

Parameters

other – Other complex number

template<typename Other>
inline void _div(const Complex<Other> &other)

Divide this complex number by another one.

Template Parameters

Other – Scalar type of the other complex number

Parameters

other – Other complex number

Private Members

T m_val[2]#

Private Static Attributes

static constexpr size_t RE = 0#
static constexpr size_t IM = 1#
namespace detail
namespace algorithm#

Functions

template<typename T>
auto normMinusOne(const T x, const T y) noexcept -> T

Calculates \( x^2 + y^2 - 1 \) for \( |x| \geq |y| \) and \( 0.5 \leq |x| < 2^{12} \).

Template Parameters

T – Template type

Parameters
  • x – First value

  • y – Second value

Returns

x * x + y * y - 1

template<bool safe = true, typename T>
auto logP1(const T x) -> T

Calculates \( \log(1 + x) \).

May be inaccurate for small inputs

Template Parameters
  • safe – If true, will check for NaNs and overflow

  • T – Template type

Parameters

x – Input value

Returns

\( \log(1 + x) \)

template<bool safe = true, typename T>
auto logHypot(const T x, const T y) noexcept -> T

Calculates \( \log(\sqrt{x^2 + y^2}) \).

Template Parameters
  • safe – If true, will check for NaNs and overflow

  • T – Template type

Parameters
  • x – Horizontal component

  • y – Vertical component

Returns

\( \log(\sqrt{x^2 + y^2}) \)

template<typename T>
auto expMul(T *pleft, T right, short exponent) -> short

Compute \(e^{\text{pleft}} \times \text{right} \times 2^{\text{exponent}}\).

Template Parameters

T – Template type

Parameters
  • pleft – Pointer to the value to be exponentiated

  • right – Multiplier for the exponentiated value

  • exponent – Exponent for the power of 2 multiplication

Returns

1 if the result is NaN or Inf, -1 otherwise

Variables

template<typename T>
static T HypotLegHuge = HypotLegHugeHelper<T>::val
template<typename T>
static T HypotLegTiny = HypotLegTinyHelper<T>::val
template<typename T>
struct HypotLegHugeHelper
#include <complex.hpp>

Public Static Attributes

static T val  =(std::is_integral_v<T>)? (::librapid::sqrt(typetraits::TypeInfo<T>::max()) / T(2)): (T(0.5) * ::librapid::sqrt(typetraits::TypeInfo<T>::max()))
template<>
struct HypotLegHugeHelper<double>
#include <complex.hpp>

Public Static Attributes

static constexpr double val = 6.703903964971298e+153
template<>
struct HypotLegHugeHelper<float>
#include <complex.hpp>

Public Static Attributes

static constexpr double val = 9.2233715e+18f
template<typename T>
struct HypotLegTinyHelper
#include <complex.hpp>

Public Static Attributes

static T val = ::librapid::sqrt(T(2) * typetraits::TypeInfo<T>::min() / typetraits::TypeInfo<T>::epsilon())
template<>
struct HypotLegTinyHelper<double>
#include <complex.hpp>

Public Static Attributes

static constexpr double val = 1.4156865331029228e-146
template<>
struct HypotLegTinyHelper<float>
#include <complex.hpp>

Public Static Attributes

static constexpr double val = 4.440892e-16f
namespace multiprec#

Functions

template<typename T>
constexpr auto addX2(const T &x, const T &y) noexcept -> Fmp<T>

Summarizes two 1x precision values combined into a 2x precision result.

This function is exact when:

  1. The result doesn’t overflow

  2. Either underflow is gradual, or no internal underflow occurs

  3. Intermediate precision is either the same as T, or greater than twice the precision of T

  4. Parameters and local variables do not retain extra intermediate precision

  5. Rounding mode is rounding to nearest.

Violation of condition 3 or 5 could lead to relative error on the order of epsilon^2.

Violation of other conditions could lead to worse results

Template Parameters

T – Template type

Parameters
  • x – First value

  • y – Second value

Returns

Sum of x and y

template<typename T>
constexpr auto addSmallX2(const T x, const T y) noexcept -> Fmp<T>

Combines two 1x precision values into a 2x precision result with the requirement of specific exponent relationship.

Requires: exponent(x) + countr_zero(significand(x)) >= exponent(y) or x == 0

The result is exact when:

  1. The requirement above is satisfied

  2. No internal overflow occurs

  3. Either underflow is gradual, or no internal underflow occurs

  4. Intermediate precision is either the same as T, or greater than twice the precision of T

  5. Parameters and local variables do not retain extra intermediate precision

  6. Rounding mode is rounding to nearest

Violation of condition 3 or 5 could lead to relative error on the order of epsilon^2.

Violation of other conditions could lead to worse results

Template Parameters

T – Template type

Parameters
  • x – First value

  • y – Second value

Returns

Sum of x and y

template<typename T>
constexpr auto addSmallX2(const T &x, const Fmp<T> &y) noexcept -> Fmp<T>

Combines a 1x precision value with a 2x precision value.

Requires: exponent(x) + countr_zero(significand(x)) >= exponent(y.val0) or x == 0

Template Parameters

T – Template type

Parameters
  • x – First value

  • y – Second value

Returns

Sum of x and y

template<typename T>
constexpr auto addX1(const Fmp<T> &x, const Fmp<T> &y) noexcept -> T

Combines two 2x precision values into a 1x precision result.

Template Parameters

T – Template type

Parameters
  • x – First value

  • y – Second value

Returns

Sum of x and y

constexpr auto highHalf(const double x) noexcept -> double

Rounds a 2x precision value to 26 significant bits.

Parameters

x – Value to round

Returns

Rounded value

constexpr double sqrError(const double x, const double prod0) noexcept

Fallback method for sqrError(const double, const double) when SIMD is not available.

template<typename T>
auto sqrError(const T x, const T prod0) noexcept -> T

Type-agnostic version of sqrError(const double, const double)

Template Parameters

T – Template type

Parameters
  • x – Input value

  • prod0 – Faithfully rounded product of x^2

auto sqrX2(const double x) noexcept -> Fmp<double>

Calculates the square of a 1x precision value and returns a 2x precision result.

The result is exact when no internal overflow or underflow occurs.

Parameters

x – Input value

Returns

2x precision square of x

template<typename T>
auto sqrX2(const T x) noexcept -> Fmp<T>

Type-agnostic version of sqrX2(const double)

Template Parameters

T – Template type

Parameters

x – Input value

Returns

2x precision square of x

template<typename Scalar>
struct Fmp
#include <complex.hpp>

Public Members

Scalar val0
Scalar val1
namespace typetraits
template<typename T>
struct TypeInfo<Complex<T>>
#include <complex.hpp>

Public Types

using Scalar = Complex<T>
using Packet = std::false_type

Public Functions

inline LIMIT_IMPL(min)
inline LIMIT_IMPL(max)
inline LIMIT_IMPL(epsilon)
inline LIMIT_IMPL(roundError)
inline LIMIT_IMPL(denormMin)
inline LIMIT_IMPL(infinity)
inline LIMIT_IMPL(quietNaN)
inline LIMIT_IMPL(signalingNaN)

Public Static Attributes

static constexpr detail::LibRapidType type = detail::LibRapidType::Scalar
static constexpr int64_t packetWidth = 0
static constexpr char name[] = "Complex"
static constexpr bool supportsArithmetic = true
static constexpr bool supportsLogical = true
static constexpr bool supportsBinary = false
static constexpr bool allowVectorisation = false
static constexpr cudaDataType_t CudaType = cudaDataType_t::CUDA_C_64F
static constexpr bool canAlign = TypeInfo<T>::canAlign
static constexpr bool canMemcpy = TypeInfo<T>::canMemcpy