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
other – Complex 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.
See also
- 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
val – Complex 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
val – Complex 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
val – Complex 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
val – Complex number
- Returns
Absolute value 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, \(z = \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, \( z = \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, \( z = \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, \( z = \text{asin}(z) \)
It calculates the complex arc sine by using the complex hyperbolic sine function.
See also
- 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, \( z = \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, \( z = \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, \( z = \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> exp(const Complex<T> &other) Compute the complex exponential of a complex number.
This function computes the complex exponential of the input complex number, \( z = 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
- 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
- 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<>
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
other – Complex 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
- Template Parameters
T – Scalar type
B – Base type
- Parameters
other – Complex 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
- Template Parameters
T – Scalar type of the complex number
B – Scalar type of the base
- Parameters
other – Complex number
base – Base of the logarithm (real)
- Returns
Logarithm of the complex number with the given base
-
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
left – Complex 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
right – Complex 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<typename T>
Complex<T> sinh(const Complex<T> &other) Calculate the hyperbolic sine of a complex number.
- Template Parameters
T – Scalar type
- Parameters
other – Complex 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
other – Complex 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
- Template Parameters
T – Scalar type
- Parameters
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
other – Complex 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
-
template<typename P>
inline void store(P *ptr) const
-
template<typename P>
inline void load(const P *ptr)
-
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
other – Complex 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
other – Complex number to add
- Returns
*this
-
inline auto operator-=(const Complex &other) -> Complex&
Inplace subtraction.
Subtract a complex number from this one
- Parameters
other – Complex number to subtract
- Returns
*this
-
inline auto operator*=(const Complex &other) -> Complex&
Inplace multiplication.
Multiply this complex number by another one
- Parameters
other – Complex number to multiply by
- Returns
*this
-
inline auto operator/=(const Complex &other) -> Complex&
Inplace division.
Divide this complex number by another one
- Parameters
other – Complex 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
-
inline auto str(const std::string &format = "{}") const -> std::string
Complex number to string.
Create a std::string representation of a complex number, formatting each component with the format string
- Parameters
format – Format string
- Returns
std::string
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
-
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
-
static constexpr double val = 6.703903964971298e+153
-
template<>
struct HypotLegHugeHelper<float> - #include <complex.hpp>
Public Static Attributes
-
static constexpr double val = 9.2233715e+18f
-
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())
-
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
-
static constexpr double val = 1.4156865331029228e-146
-
template<>
struct HypotLegTinyHelper<float> - #include <complex.hpp>
Public Static Attributes
-
static constexpr double val = 4.440892e-16f
-
static constexpr double val = 4.440892e-16f
-
template<typename T>
-
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:
The result doesn’t overflow
Either underflow is gradual, or no internal underflow occurs
Intermediate precision is either the same as T, or greater than twice the precision of T
Parameters and local variables do not retain extra intermediate precision
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:
The requirement above is satisfied
No internal overflow occurs
Either underflow is gradual, or no internal underflow occurs
Intermediate precision is either the same as T, or greater than twice the precision of T
Parameters and local variables do not retain extra intermediate precision
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>
-
template<typename T>
-
namespace algorithm#
-
namespace typetraits
-
template<typename T>
struct TypeInfo<Complex<T>> - #include <complex.hpp>
Public Types
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 = TypeInfo<typename TypeInfo<T>::Scalar>::packetWidth
-
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
-
inline LIMIT_IMPL(min)
-
template<typename T>
-
template<typename T>