scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
scifir::complex_number< T > Class Template Reference

#include <complex_number.hpp>

Public Member Functions

 complex_number ()
 
 complex_number (const complex_number< T > &x)
 
 complex_number (complex_number< T > &&x)
 
 complex_number (const scalar_unit &x, const scalar_unit &y)
 
 complex_number (const string &x, const string &y)
 
 complex_number (const string &init_complex_number)
 
complex_number< T > & operator= (const complex_number< T > &x)
 
complex_number< T > & operator= (complex_number< T > &&x)
 
template<typename U >
complex_number< Toperator+ (const complex_number< U > &x) const
 
template<typename U >
complex_number< Toperator- (const complex_number< U > &x) const
 
template<typename U >
complex_number< scalar_unitoperator* (const complex_number< U > &x) const
 
template<typename U >
complex_number< scalar_unitoperator/ (const complex_number< U > &x) const
 
template<typename U >
void operator+= (const complex_number< U > &x)
 
template<typename U >
void operator-= (const complex_number< U > &x)
 
complex_number< Tget_conjugate () const
 
T get_r () const
 
angle get_argument () const
 
complex_number< scalar_unitget_reciprocal () const
 
string display (int number_of_decimals=2) const
 

Public Attributes

T real
 
T imaginary
 

Detailed Description

template<class T>
class scifir::complex_number< T >

Definition at line 19 of file complex_number.hpp.

Constructor & Destructor Documentation

◆ complex_number() [1/6]

template<class T >
scifir::complex_number< T >::complex_number ( )
inline

◆ complex_number() [2/6]

template<class T >
scifir::complex_number< T >::complex_number ( const complex_number< T > &  x)
inline

Definition at line 25 of file complex_number.hpp.

25 : real(x.real),imaginary(x.imaginary)
26 {}

◆ complex_number() [3/6]

template<class T >
scifir::complex_number< T >::complex_number ( complex_number< T > &&  x)
inline

Definition at line 28 of file complex_number.hpp.

28 : real(std::move(x.real)),imaginary(std::move(x.imaginary))
29 {}

◆ complex_number() [4/6]

template<class T >
scifir::complex_number< T >::complex_number ( const scalar_unit x,
const scalar_unit y 
)
inlineexplicit

Definition at line 31 of file complex_number.hpp.

31 : real(x),imaginary(y)
32 {}

◆ complex_number() [5/6]

template<class T >
scifir::complex_number< T >::complex_number ( const string x,
const string y 
)
inlineexplicit

Definition at line 34 of file complex_number.hpp.

34 : real(T(x)),imaginary(T(y))
35 {}

◆ complex_number() [6/6]

template<class T >
scifir::complex_number< T >::complex_number ( const string init_complex_number)
inlineexplicit

Definition at line 37 of file complex_number.hpp.

38 {
39 if (init_complex_number.find("+") != string::npos or init_complex_number.find("-") != string::npos)
40 {
41 vector<string> numbers;
42 boost::split(numbers,init_complex_number,boost::is_any_of("+-"));
43 if (numbers.size() == 2)
44 {
45 boost::trim(numbers[0]);
46 boost::trim(numbers[1]);
47 if (numbers[1].substr(numbers[1].length() - 3) == "(i)")
48 {
49 real = T(numbers[0]);
50 imaginary = T(numbers[1].substr(0,numbers[1].length() - 3));
51 if (init_complex_number.find("-") != string::npos)
52 {
53 imaginary *= -1;
54 }
55 }
56 else
57 {
58 real = T();
59 imaginary = T();
60 }
61 }
62 }
63 else
64 {
65 real = T();
66 imaginary = T();
67 }
68 }

Member Function Documentation

◆ display()

template<class T >
string scifir::complex_number< T >::display ( int  number_of_decimals = 2) const
inline

Definition at line 157 of file complex_number.hpp.

158 {
159 ostringstream output;
160 output << real.display(number_of_decimals);
161 if (imaginary >= 0)
162 {
163 output << " + ";
164 }
165 else
166 {
167 output << " - ";
168 }
169 output << display_float(std::abs(imaginary.get_value()),number_of_decimals) << " " << imaginary.display_dimensions() << "(i)";
170 return output.str();
171 }
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36

◆ get_argument()

template<class T >
angle scifir::complex_number< T >::get_argument ( ) const
inline

Definition at line 134 of file complex_number.hpp.

135 {
136 if (imaginary != 0 and real > 0)
137 {
138 return angle(2 * scifir::atan(float(imaginary / (real + scifir::sqrt((scifir::pow(real,2) + scifir::pow(imaginary,2)))))));
139 }
140 else if (real < 0 and imaginary == 0)
141 {
142 return angle(180.0f);
143 }
144 else
145 {
146 return angle();
147 }
148 }
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
angle atan(float x)
Calculates the atan of some value x and returns the result as angle in degrees.
Definition angle.cpp:451
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416

◆ get_conjugate()

template<class T >
complex_number< T > scifir::complex_number< T >::get_conjugate ( ) const
inline

Definition at line 124 of file complex_number.hpp.

125 {
126 return complex_number<T>(real,imaginary * -1);
127 }

◆ get_r()

template<class T >
T scifir::complex_number< T >::get_r ( ) const
inline

Definition at line 129 of file complex_number.hpp.

130 {
132 }

◆ get_reciprocal()

template<class T >
complex_number< scalar_unit > scifir::complex_number< T >::get_reciprocal ( ) const
inline

Definition at line 150 of file complex_number.hpp.

151 {
152 scalar_unit new_real = real / ((real^2) + (imaginary^2));
153 scalar_unit new_imaginary = (-1 * imaginary) / ((real^2) + (imaginary^2));
154 return complex_number<scalar_unit>(new_real,new_imaginary);
155 }

◆ operator*()

template<class T >
template<typename U >
complex_number< scalar_unit > scifir::complex_number< T >::operator* ( const complex_number< U > &  x) const
inline

Definition at line 97 of file complex_number.hpp.

98 {
99 return complex_number<scalar_unit>(real * x.real - imaginary * x.imaginary,real * x.imaginary + imaginary * x.real);
100 }

◆ operator+()

template<class T >
template<typename U >
complex_number< T > scifir::complex_number< T >::operator+ ( const complex_number< U > &  x) const
inline

Definition at line 85 of file complex_number.hpp.

86 {
87 return complex_number<T>(T(real + x.real),T(imaginary + x.imaginary));
88 }

◆ operator+=()

template<class T >
template<typename U >
void scifir::complex_number< T >::operator+= ( const complex_number< U > &  x)
inline

Definition at line 111 of file complex_number.hpp.

112 {
113 real += x.real;
114 imaginary += x.imaginary;
115 }

◆ operator-()

template<class T >
template<typename U >
complex_number< T > scifir::complex_number< T >::operator- ( const complex_number< U > &  x) const
inline

Definition at line 91 of file complex_number.hpp.

92 {
93 return complex_number<T>(T(real - x.real),T(imaginary - x.imaginary));
94 }

◆ operator-=()

template<class T >
template<typename U >
void scifir::complex_number< T >::operator-= ( const complex_number< U > &  x)
inline

Definition at line 118 of file complex_number.hpp.

119 {
120 real -= x.real;
121 imaginary -= x.imaginary;
122 }

◆ operator/()

template<class T >
template<typename U >
complex_number< scalar_unit > scifir::complex_number< T >::operator/ ( const complex_number< U > &  x) const
inline

Definition at line 103 of file complex_number.hpp.

104 {
105 scalar_unit new_real = (real * x.real + x.imaginary * imaginary) / ((real^2) + (imaginary^2));
106 scalar_unit new_imaginary = (x.imaginary * real - x.real * imaginary) / ((real^2) + (imaginary^2));
107 return complex_number<scalar_unit>(new_real,new_imaginary);
108 }

◆ operator=() [1/2]

template<class T >
complex_number< T > & scifir::complex_number< T >::operator= ( complex_number< T > &&  x)
inline

Definition at line 77 of file complex_number.hpp.

78 {
79 real = std::move(x.real);
80 imaginary = std::move(x.imaginary);
81 return *this;
82 }

◆ operator=() [2/2]

template<class T >
complex_number< T > & scifir::complex_number< T >::operator= ( const complex_number< T > &  x)
inline

Definition at line 70 of file complex_number.hpp.

71 {
72 real = x.real;
73 imaginary = x.imaginary;
74 return *this;
75 }

Member Data Documentation

◆ imaginary

template<class T >
T scifir::complex_number< T >::imaginary

Definition at line 174 of file complex_number.hpp.

◆ real

template<class T >
T scifir::complex_number< T >::real

Definition at line 173 of file complex_number.hpp.


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