MathLib
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BasicComplex< T > Class Template Reference

#include <math/Complex.hpp>

Public Types

Types
using value_type = T
 The underlying implementation type.
 

Public Member Functions

constexpr BasicComplex< T > conjugate () const
 
BasicComplex< T > pow (T exponent) const
 Computes this BasicComplex raised to a real power.
 
BasicComplex< T > pow (int exponent) const
 
BasicComplex< T > pow (BasicComplex< T > exponent) const
 
BasicComplex< T > exp () const
 
BasicComplex< T > log () const
 
BasicComplex< T > log10 () const
 
T normSquared () const
 
T norm () const
 
T magnitudeSquared () const
 
T magnitude () const
 
constexpr BasicComplex< T > normalized () const
 
BasicComplex< T > inverse () const
 
BasicRadian< T > angle () const
 
bool isUnit () const
 
bool isUnit (T tolerance) const
 
bool isZero () const
 
bool isZero (T tolerance) const
 
bool isPure () const
 
constexpr std::complex< T > asStdComplex () const
 
Constructors
constexpr BasicComplex ()=default
 
constexpr BasicComplex (T real_number)
 Constructs a BasicComplex equivalent to the given real number.
 
constexpr BasicComplex (T real_part, T imaginary_part)
 
constexpr BasicComplex (BasicRadian< T > real_part, BasicRadian< T > imaginary_part)
 
constexpr BasicComplex (std::complex< T > c)
 Conversion from std::complex.
 
Element Access
constexpr const T & real () const
 
constexpr void real (T r)
 
constexpr const T & i () const
 
constexpr void i (T r)
 
constexpr const T & imaginary () const
 Extracts the imaginary part of a BasicComplex.
 
constexpr void imaginary (T r)
 
Invalid Value Check
bool isNaN () const
 
bool isInf () const
 
Conversion Operators
 operator std::complex< T > () const
 

Static Public Member Functions

Constants
static constexpr BasicComplex< T > identity ()
 BasicComplex representation of the real number 1.
 
static constexpr BasicComplex< T > zero ()
 BasicComplex representation of the real number 0.
 
static constexpr BasicComplex< T > unit_real ()
 
static constexpr BasicComplex< T > unit_i ()
 
Convenience Creation Functions
static constexpr BasicComplex< T > make_pure (T i)
 
static constexpr BasicComplex< T > encode_point (T x, T y)
 
static constexpr BasicComplex< T > make_rotation (BasicRadian< T > radians)
 

Friends

Equality
constexpr bool operator== (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
template<std::floating_point OT = T>
constexpr bool approximately_equal_to (const BasicComplex< T > &value_to_test, const BasicComplex< T > &value_it_should_be, OT tolerance=OT{0.0002})
 
Operators
constexpr BasicComplex< T > operator* (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
template<std::floating_point OT>
constexpr BasicComplex< T > operator* (const BasicComplex< T > &complex, OT scalar)
 
constexpr BasicComplex< T > operator/ (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
template<std::floating_point OT>
constexpr BasicComplex< T > operator/ (const BasicComplex< T > &complex, OT scalar)
 
constexpr BasicComplex< T > operator+ (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
template<std::floating_point OT>
constexpr BasicComplex< T > operator+ (const BasicComplex< T > &complex, OT scalar)
 
constexpr BasicComplex< T > operator- (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
template<std::floating_point OT>
constexpr BasicComplex< T > operator- (const BasicComplex< T > &complex, OT scalar)
 
constexpr BasicComplex< T > operator- (const BasicComplex< T > &q)
 
Check
template<std::floating_point OT = T>
bool check_if_equal (const BasicComplex< T > &input, const BasicComplex< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
bool check_if_not_equal (const BasicComplex< T > &input, const BasicComplex< T > &near_to, OT tolerance=OT{0.0002})
 
Assert
template<std::floating_point OT = T>
void CHECK_IF_EQUAL (const BasicComplex< T > &input, const BasicComplex< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
void CHECK_IF_NOT_EQUAL (const BasicComplex< T > &input, const BasicComplex< T > &near_to, OT tolerance=OT{0.0002})
 
template<std::floating_point OT = T>
void CHECK_IF_ZERO (const BasicComplex< T > &input, OT tolerance=OT{0.0002})
 
Global Functions
constexpr T dot (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
constexpr T dot_normalized (const BasicComplex< T > &left, const BasicComplex< T > &right)
 
constexpr BasicComplex< T > passively_rotate_encoded_point (const BasicComplex< T > &rotation, const BasicComplex< T > &encoded_point)
 
constexpr BasicComplex< T > compose_rotations (const BasicComplex< T > &rotation_1, const BasicComplex< T > &rotation_2)
 
constexpr BasicComplex< T > normalized (const BasicComplex< T > &input)
 
constexpr BasicRadian< T > arg (const BasicComplex< T > &input)
 
constexpr BasicComplex< T > polar (T m, BasicRadian< T > angle=BasicRadian< T >{})
 
constexpr T accumulate (const BasicComplex< T > &input)
 
constexpr BasicComplex< T > slerp (const BasicComplex< T > &begin, const BasicComplex< T > &end, T percent)
 
std::string format (const BasicComplex< T > &input)
 
constexpr BasicComplex< T > conjugate (const BasicComplex< T > &input)
 
constexpr BasicComplex< T > log (const BasicComplex< T > &input)
 
constexpr BasicComplex< T > log10 (const BasicComplex< T > &input)
 
BasicComplex< T > exp (const BasicComplex< T > &input)
 
BasicComplex< T > pow (const BasicComplex< T > &input, T p)
 
BasicComplex< T > pow (const BasicComplex< T > &input, int p)
 
BasicComplex< T > pow (const BasicComplex< T > &input, const BasicComplex< T > &p)
 
Trigonometric Functions
BasicComplex< T > sin (BasicComplex< T > c)
 
BasicComplex< T > cos (BasicComplex< T > c)
 
BasicComplex< T > tan (BasicComplex< T > c)
 
BasicComplex< T > asin (BasicComplex< T > c)
 
BasicComplex< T > acos (BasicComplex< T > c)
 
BasicComplex< T > atan (BasicComplex< T > c)
 
BasicComplex< T > sinh (BasicComplex< T > c)
 
BasicComplex< T > cosh (BasicComplex< T > c)
 
BasicComplex< T > tanh (BasicComplex< T > c)
 
BasicComplex< T > asinh (BasicComplex< T > c)
 
BasicComplex< T > acosh (BasicComplex< T > c)
 
BasicComplex< T > atanh (BasicComplex< T > c)
 

Related Symbols

(Note that these are not member symbols.)

Type Aliases
using Complexf = BasicComplex< float >
 
using Complexd = BasicComplex< double >
 
using Complex = BasicComplex< double >
 
using Complexl = BasicComplex< long double >
 

Detailed Description

template<std::floating_point T>
class Math::BasicComplex< T >

A mathematical complex number

Note
A complex number is a 2-dimensional object that extends the real number system. It is commonly used in various fields of mathematics and engineering.

Definition at line 31 of file Complex.hpp.

Member Typedef Documentation

◆ value_type

template<std::floating_point T>
using value_type = T

The underlying implementation type.

Definition at line 37 of file Complex.hpp.

Constructor & Destructor Documentation

◆ BasicComplex() [1/5]

template<std::floating_point T>
constexpr BasicComplex ( )
constexprdefault

◆ BasicComplex() [2/5]

template<std::floating_point T>
constexpr BasicComplex ( T  real_number)
inlineconstexpr

Constructs a BasicComplex equivalent to the given real number.

Definition at line 44 of file Complex.hpp.

◆ BasicComplex() [3/5]

template<std::floating_point T>
constexpr BasicComplex ( T  real_part,
T  imaginary_part 
)
inlineconstexpr

Definition at line 45 of file Complex.hpp.

◆ BasicComplex() [4/5]

template<std::floating_point T>
constexpr BasicComplex ( BasicRadian< T >  real_part,
BasicRadian< T >  imaginary_part 
)
inlineconstexpr

Definition at line 46 of file Complex.hpp.

◆ BasicComplex() [5/5]

template<std::floating_point T>
constexpr BasicComplex ( std::complex< T >  c)
inlineconstexpr

Conversion from std::complex.

Definition at line 52 of file Complex.hpp.

Member Function Documentation

◆ angle()

template<std::floating_point T>
BasicRadian< T > angle ( ) const
inline

Definition at line 135 of file Complex.hpp.

◆ asStdComplex()

template<std::floating_point T>
constexpr std::complex< T > asStdComplex ( ) const
inlineconstexpr

Definition at line 206 of file Complex.hpp.

◆ conjugate()

template<std::floating_point T>
constexpr BasicComplex< T > conjugate ( ) const
inlineconstexpr

Definition at line 67 of file Complex.hpp.

◆ encode_point()

template<std::floating_point T>
static constexpr BasicComplex< T > encode_point ( T  x,
T  y 
)
inlinestaticconstexpr

Definition at line 191 of file Complex.hpp.

◆ exp()

template<std::floating_point T>
BasicComplex< T > exp ( ) const
inline

Computes the exponential form of this BasicComplex

Note
It is possible for this routine to output a non-unit BasicComplex when given a unit BasicComplex as input. It is for this reason that the implementation of log() has been adjusted to automatically handle non-unit Quaternions.

Definition at line 97 of file Complex.hpp.

◆ i() [1/2]

template<std::floating_point T>
constexpr const T & i ( ) const
inlineconstexpr

Definition at line 146 of file Complex.hpp.

◆ i() [2/2]

template<std::floating_point T>
constexpr void i ( T  r)
inlineconstexpr

Definition at line 147 of file Complex.hpp.

◆ identity()

template<std::floating_point T>
static constexpr BasicComplex< T > identity ( )
inlinestaticconstexpr

BasicComplex representation of the real number 1.

Definition at line 59 of file Complex.hpp.

◆ imaginary() [1/2]

template<std::floating_point T>
constexpr const T & imaginary ( ) const
inlineconstexpr

Extracts the imaginary part of a BasicComplex.

Definition at line 150 of file Complex.hpp.

◆ imaginary() [2/2]

template<std::floating_point T>
constexpr void imaginary ( T  r)
inlineconstexpr

Definition at line 151 of file Complex.hpp.

◆ inverse()

template<std::floating_point T>
BasicComplex< T > inverse ( ) const
inline

Definition at line 133 of file Complex.hpp.

◆ isInf()

template<std::floating_point T>
bool isInf ( ) const
inline

Definition at line 170 of file Complex.hpp.

◆ isNaN()

template<std::floating_point T>
bool isNaN ( ) const
inline

Definition at line 166 of file Complex.hpp.

◆ isPure()

template<std::floating_point T>
bool isPure ( ) const
inline

Definition at line 161 of file Complex.hpp.

◆ isUnit() [1/2]

template<std::floating_point T>
bool isUnit ( ) const
inline

Definition at line 154 of file Complex.hpp.

◆ isUnit() [2/2]

template<std::floating_point T>
bool isUnit ( T  tolerance) const
inline

Definition at line 155 of file Complex.hpp.

◆ isZero() [1/2]

template<std::floating_point T>
bool isZero ( ) const
inline

Definition at line 157 of file Complex.hpp.

◆ isZero() [2/2]

template<std::floating_point T>
bool isZero ( T  tolerance) const
inline

Definition at line 158 of file Complex.hpp.

◆ log()

template<std::floating_point T>
BasicComplex< T > log ( ) const
inline

Computes the log base e of this BasicComplex

Note
We handle non-unit Complex in this version so that we can satisfy the relationship: log( exp( x ) ) == x

Definition at line 107 of file Complex.hpp.

◆ log10()

template<std::floating_point T>
BasicComplex< T > log10 ( ) const
inline

Computes the log base 10 of this BasicComplex

Definition at line 115 of file Complex.hpp.

◆ magnitude()

template<std::floating_point T>
T magnitude ( ) const
inline

Definition at line 124 of file Complex.hpp.

◆ magnitudeSquared()

template<std::floating_point T>
T magnitudeSquared ( ) const
inline

Definition at line 123 of file Complex.hpp.

◆ make_pure()

template<std::floating_point T>
static constexpr BasicComplex< T > make_pure ( T  i)
inlinestaticconstexpr

Construct a pure BasicComplex

Parameters
iThe value to set the imaginary component to
Postcondition
output.real() == 0
output.imaginary() == i
Note
A pure BasicComplex is one in which the real component is 0.

Definition at line 189 of file Complex.hpp.

◆ make_rotation()

template<std::floating_point T>
static constexpr BasicComplex< T > make_rotation ( BasicRadian< T >  radians)
inlinestaticconstexpr

Enocde a rotation into a BasicComplex

Parameters
radiansThe amount of rotation to apply (in radians)
Note
This ends up being like polar(), but we assume the magnitude is 1, so we don't take that as an input and we don't compute it in the output.

Definition at line 200 of file Complex.hpp.

◆ norm()

template<std::floating_point T>
T norm ( ) const
inline

Definition at line 121 of file Complex.hpp.

◆ normalized()

template<std::floating_point T>
constexpr BasicComplex< T > normalized ( ) const
inlineconstexpr

Definition at line 126 of file Complex.hpp.

◆ normSquared()

template<std::floating_point T>
T normSquared ( ) const
inline

Definition at line 120 of file Complex.hpp.

◆ operator std::complex< T >()

template<std::floating_point T>
operator std::complex< T > ( ) const
inline

Definition at line 211 of file Complex.hpp.

◆ pow() [1/3]

template<std::floating_point T>
BasicComplex< T > pow ( BasicComplex< T >  exponent) const
inline

Definition at line 85 of file Complex.hpp.

◆ pow() [2/3]

template<std::floating_point T>
BasicComplex< T > pow ( int  exponent) const
inline

Definition at line 80 of file Complex.hpp.

◆ pow() [3/3]

template<std::floating_point T>
BasicComplex< T > pow ( T  exponent) const
inline

Computes this BasicComplex raised to a real power.

Definition at line 73 of file Complex.hpp.

◆ real() [1/2]

template<std::floating_point T>
constexpr const T & real ( ) const
inlineconstexpr

Definition at line 143 of file Complex.hpp.

◆ real() [2/2]

template<std::floating_point T>
constexpr void real ( T  r)
inlineconstexpr

Definition at line 144 of file Complex.hpp.

◆ unit_i()

template<std::floating_point T>
static constexpr BasicComplex< T > unit_i ( )
inlinestaticconstexpr

Definition at line 64 of file Complex.hpp.

◆ unit_real()

template<std::floating_point T>
static constexpr BasicComplex< T > unit_real ( )
inlinestaticconstexpr

Definition at line 63 of file Complex.hpp.

◆ zero()

template<std::floating_point T>
static constexpr BasicComplex< T > zero ( )
inlinestaticconstexpr

BasicComplex representation of the real number 0.

Definition at line 62 of file Complex.hpp.

Friends And Related Symbol Documentation

◆ accumulate

template<std::floating_point T>
constexpr T accumulate ( const BasicComplex< T > &  input)
friend

Sums up the components of input

Parameters
inputThe BasicComplex to operate on
Returns
The sum of all the components

Definition at line 542 of file Complex.hpp.

◆ acos

template<std::floating_point T>
BasicComplex< T > acos ( BasicComplex< T >  c)
friend

Definition at line 651 of file Complex.hpp.

◆ acosh

template<std::floating_point T>
BasicComplex< T > acosh ( BasicComplex< T >  c)
friend

Definition at line 681 of file Complex.hpp.

◆ approximately_equal_to

template<std::floating_point T>
template<std::floating_point OT = T>
constexpr bool approximately_equal_to ( const BasicComplex< T > &  value_to_test,
const BasicComplex< T > &  value_it_should_be,
OT  tolerance = OT{0.0002} 
)
friend

Compares two BasicComplex inputs equal, component-wise, to within a tolerance

Parameters
value_to_test
value_it_should_be
toleranceHow close they should be to be considered equal
Returns
true if they are equal
See also
Equality

Definition at line 247 of file Complex.hpp.

◆ arg

template<std::floating_point T>
constexpr BasicRadian< T > arg ( const BasicComplex< T > &  input)
friend

Computes the phase-angle (in radians of a Complex)

Note
This is meant to mirror the behavior of std::arg( std::complex )

Definition at line 519 of file Complex.hpp.

◆ asin

template<std::floating_point T>
BasicComplex< T > asin ( BasicComplex< T >  c)
friend

Definition at line 646 of file Complex.hpp.

◆ asinh

template<std::floating_point T>
BasicComplex< T > asinh ( BasicComplex< T >  c)
friend

Definition at line 676 of file Complex.hpp.

◆ atan

template<std::floating_point T>
BasicComplex< T > atan ( BasicComplex< T >  c)
friend

Definition at line 656 of file Complex.hpp.

◆ atanh

template<std::floating_point T>
BasicComplex< T > atanh ( BasicComplex< T >  c)
friend

Definition at line 686 of file Complex.hpp.

◆ compose_rotations

template<std::floating_point T>
constexpr BasicComplex< T > compose_rotations ( const BasicComplex< T > &  rotation_1,
const BasicComplex< T > &  rotation_2 
)
friend

Performs a concatenation of two rotations

Parameters
rotation_1The first rotation to perform
rotation_2The second rotation to perform

Definition at line 498 of file Complex.hpp.

◆ conjugate

template<std::floating_point T>
constexpr BasicComplex< T > conjugate ( const BasicComplex< T > &  input)
friend

Computes the conjugate of the input

Note
This will just call input.conjugate()

Definition at line 573 of file Complex.hpp.

◆ cos

template<std::floating_point T>
BasicComplex< T > cos ( BasicComplex< T >  c)
friend

Definition at line 636 of file Complex.hpp.

◆ cosh

template<std::floating_point T>
BasicComplex< T > cosh ( BasicComplex< T >  c)
friend

Definition at line 666 of file Complex.hpp.

◆ dot

template<std::floating_point T>
constexpr T dot ( const BasicComplex< T > &  left,
const BasicComplex< T > &  right 
)
friend

Calculates the dot product of two Quaternions

Note
In this case, the Quaternions are just treated as separate 4-tuples and the dot product of those are calculated.

Definition at line 458 of file Complex.hpp.

◆ dot_normalized

template<std::floating_point T>
constexpr T dot_normalized ( const BasicComplex< T > &  left,
const BasicComplex< T > &  right 
)
friend

Definition at line 464 of file Complex.hpp.

◆ exp

template<std::floating_point T>
BasicComplex< T > exp ( const BasicComplex< T > &  input)
friend

Computes the exponential of the input

Note
This will just call input.exp()

Definition at line 600 of file Complex.hpp.

◆ format

template<std::floating_point T>
std::string format ( const BasicComplex< T > &  input)
friend

Definition at line 564 of file Complex.hpp.

◆ log

template<std::floating_point T>
constexpr BasicComplex< T > log ( const BasicComplex< T > &  input)
friend

Computes the log of the input

Note
This will just call input.log()

Definition at line 582 of file Complex.hpp.

◆ log10

template<std::floating_point T>
constexpr BasicComplex< T > log10 ( const BasicComplex< T > &  input)
friend

Computes the log base 10 of the input

Note
This will just call input.log10()

Definition at line 591 of file Complex.hpp.

◆ normalized

template<std::floating_point T>
constexpr BasicComplex< T > normalized ( const BasicComplex< T > &  input)
friend

Creates the normalized form of a Quaternion

Parameters
inputThe Quaternion to normalize
Returns
The normalized version of input

Definition at line 510 of file Complex.hpp.

◆ operator==

template<std::floating_point T>
constexpr bool operator== ( const BasicComplex< T > &  left,
const BasicComplex< T > &  right 
)
friend

Defines equality of two Quaternions

Note
Uses approximately_equal_to under-the-hood
Use C++20's ability to generate the operator !=() from operator ==()
See also
Equality

Definition at line 231 of file Complex.hpp.

◆ passively_rotate_encoded_point

template<std::floating_point T>
constexpr BasicComplex< T > passively_rotate_encoded_point ( const BasicComplex< T > &  rotation,
const BasicComplex< T > &  encoded_point 
)
friend

Rotates the encoded point using the given rotation

Parameters
rotationThe input rotation
encoded_pointThe input point to be rotated
Returns
The passively rotated encoded point
Precondition
rotation is a unit BasicComplex. encoded_point is an encoded_point
Postcondition
The output is a pure BasicComplex
Note
This is a passive rotation, meaning that the coordinate system is rotated with respect to the point. This is also known as a local rotation.

Definition at line 485 of file Complex.hpp.

◆ polar

template<std::floating_point T>
constexpr BasicComplex< T > polar ( T  m,
BasicRadian< T >  angle = BasicRadian<T>{} 
)
friend

Constructs a unit Complex from the given axis and angle

Parameters
mThe magnitude of the Complex to create
angleThe amount of rotation to apply (in radians)
Note
This is meant to mirror the behavior of the std::complex version of std::polar()

Definition at line 531 of file Complex.hpp.

◆ pow [1/3]

template<std::floating_point T>
BasicComplex< T > pow ( const BasicComplex< T > &  input,
const BasicComplex< T > &  p 
)
friend

Definition at line 620 of file Complex.hpp.

◆ pow [2/3]

template<std::floating_point T>
BasicComplex< T > pow ( const BasicComplex< T > &  input,
int  p 
)
friend

Definition at line 615 of file Complex.hpp.

◆ pow [3/3]

template<std::floating_point T>
BasicComplex< T > pow ( const BasicComplex< T > &  input,
T  p 
)
friend

Computes the power of the input

Note
This will just call input.exp()

Definition at line 610 of file Complex.hpp.

◆ sin

template<std::floating_point T>
BasicComplex< T > sin ( BasicComplex< T >  c)
friend

Definition at line 631 of file Complex.hpp.

◆ sinh

template<std::floating_point T>
BasicComplex< T > sinh ( BasicComplex< T >  c)
friend

Definition at line 661 of file Complex.hpp.

◆ slerp

template<std::floating_point T>
constexpr BasicComplex< T > slerp ( const BasicComplex< T > &  begin,
const BasicComplex< T > &  end,
T  percent 
)
friend

Calculates the Spherical Linear Interpolation betwee two Complex numbers

Parameters
beginOrigin value
endDestination value
percent[0..1] Represents the percentage to interpolate

Definition at line 553 of file Complex.hpp.

◆ tan

template<std::floating_point T>
BasicComplex< T > tan ( BasicComplex< T >  c)
friend

Definition at line 641 of file Complex.hpp.

◆ tanh

template<std::floating_point T>
BasicComplex< T > tanh ( BasicComplex< T >  c)
friend

Definition at line 671 of file Complex.hpp.


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