SH4ZAM! 0.7.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_complex.hpp
Go to the documentation of this file.
1/*! \file
2 \brief Complex number C++ API
3 \ingroup complex
4
5 This file contains the C++ layer for wrapping the Complex
6 Number C API. The major thing that it adds in C++ is convenient
7 overloaded operators for performing arithmetic on complex numbers
8 using the regular arithmetic operators, rather than having to make
9 function calls which implement them, as in C.
10
11 \author 2026 Falco Girgis
12 \copyright MIT License
13
14 \todo
15 - custom literals
16 - array index accessors?
17 - iterator support?
18*/
19
20#ifndef SHZ_COMPLEX_HPP
21#define SHZ_COMPLEX_HPP
22
23#include <compare>
24
25#include "shz_complex.h"
26
27namespace shz {
28
29 //! C++ wrapper around a floating-point complex number, real/imaginary pair.
30 struct complex: public shz_complex_t {
31
32 /*! \name Constructors
33 \brief Members for initializing and constructing.
34 @{
35 */
36
37 //! Default constructor.
38 complex() noexcept = default;
39
40 //! Default copy constructor.
41 complex(const complex& rhs) noexcept = default;
42
43 //! Value constructor, sets the imaginary component to `0` if none is supplied.
44 SHZ_FORCE_INLINE complex(float re, float im = 0.0f) noexcept:
45 shz_complex_t({ re, im }) {}
46
47 //! Converting constructor for initializing from the C base type.
48 SHZ_FORCE_INLINE complex(const shz_complex_t& cplx) noexcept:
49 complex(cplx.real, cplx.imag) {}
50
51 //! Converting constructor for initialization from a volatile value type.
52 SHZ_FORCE_INLINE complex(const volatile shz_complex_t& cplx) noexcept:
53 complex(cplx.real, cplx.imag) {}
54
55 //! @}
56
57 /*! \name Member Operators
58 \brief Overloaded operators defined as member functions.
59 @{
60 */
61#ifdef SHZ_CPP23
62 //! Overloaded subscript operator -- allows for indexing complex numbers like a 2-element array.
63 SHZ_FORCE_INLINE auto&& operator[](this auto&& self, size_t index) noexcept {
64 return std::forward_like<decltype(self)>(reinterpret_cast<const float*>(&self)[index]);
65 }
66
67 //! Returns an iterator to the beginning of the vector -- For STL support.
68 SHZ_FORCE_INLINE auto begin(this auto&& self) noexcept {
69 return std::forward_like<decltype(self)>(&self[0]);
70 }
71
72 //! Returns an iterator to the end of the vector -- For STL support.
73 SHZ_FORCE_INLINE auto end(this auto&& self) noexcept {
74 return std::forward_like<decltype(self)>(&self[2]);
75 }
76
77 //! Overloaded space-ship operator, for generic lexicographical comparison of vectors.
78 friend auto operator<=>(const complex& lhs, const complex& rhs) noexcept {
80 }
81
82 //! Generic overloaded operator for assigning a generic "this" type to volatile reference to base C type.
83 template<typename T>
84 SHZ_FORCE_INLINE auto&& operator=(this T&& self, volatile shz_complex_t other) noexcept {
85 const_cast<std::remove_cvref_t<T>&>(self) = complex(const_cast<shz_complex_t&>(other));
86 return std::forward<T>(self);
87 }
88#endif
89
90 //! Adds and accumulates \p rhs onto the given complex number.
91 SHZ_FORCE_INLINE complex& operator+=(const complex& rhs) noexcept {
92 return (*this = shz_caddf(*this, rhs));
93 }
94
95 //! Subtracts \p rhs from the given complex number, assigning it to the result.
96 SHZ_FORCE_INLINE complex& operator-=(const complex& rhs) noexcept {
97 return (*this = shz_csubf(*this, rhs));
98 }
99
100 //! Multiplies and accumulates \p rhs by the given complex number.
101 SHZ_FORCE_INLINE complex& operator*=(const complex& rhs) noexcept {
102 return (*this = shz_cmulf(*this, rhs));
103 }
104
105 //! Multiplies and accumulates the given complex number by \p scalar.
106 SHZ_FORCE_INLINE complex& operator*=(float scale) noexcept {
107 return (*this = shz_cscalef(*this, scale));
108 }
109
110 //! Divides the given complex number by \p rhs, assigning it to the result.
111 SHZ_FORCE_INLINE complex& operator/=(const complex& rhs) noexcept {
112 return (*this = shz_cdivf(*this, rhs));
113 }
114
115 //! @}
116 };
117
118 //! POSIX-style C++ alias, for those who dig that kind of type name.
119 using complex_t = complex;
120
121 /*! \name Global Operators
122 \brief Globally-defined overloaded operators.
123 @{
124 */
125
126 //! Adds the two complex numbers, \p lhs and \p rhs, returning the result.
127 SHZ_FORCE_INLINE complex operator+(const complex& lhs, const complex& rhs) noexcept {
128 return shz_caddf(lhs, rhs);
129 }
130
131 //! Subtracts \p rhs from \p lhs, returning the complex result.
132 SHZ_FORCE_INLINE complex operator-(const complex& lhs, const complex& rhs) noexcept {
133 return shz_csubf(lhs, rhs);
134 }
135
136 //! Multiplies \p lhs by \p rhs, returning the complex result.
137 SHZ_FORCE_INLINE complex operator*(const complex& lhs, const complex& rhs) noexcept {
138 return shz_cmulf(lhs, rhs);
139 }
140
141 //! Multiplies \p lhs by a complex number with the real component given as \p rhs and no imaginary component.
142 SHZ_FORCE_INLINE complex operator*(const complex& lhs, float rhs) noexcept {
143 return shz_cscalef(lhs, rhs);
144 }
145
146 //! Divides \p lhs by \p rhs, returning the complex result.
147 SHZ_FORCE_INLINE complex operator/(const complex& lhs, const complex& rhs) noexcept {
148 return shz_cdivf(lhs, rhs);
149 }
150
151 //! Divides \p lhs by a complex number with the real compoonent given as \p rhs and no imaginary component.
152 SHZ_FORCE_INLINE complex operator/(const complex& lhs, float rhs) noexcept {
153 return shz_cscalef(lhs, shz_invf(rhs));
154 }
155
156 //! Returns true if the two complex numbers are approximately equal.
157 SHZ_FORCE_INLINE bool operator==(const complex& lhs, const complex& rhs) noexcept {
158 return shz_cequalf(lhs, rhs);
159 }
160
161 //! Returns true if the two complex numbers are approximately inequal.
162 SHZ_FORCE_INLINE bool operator!=(const complex& lhs, const complex& rhs) noexcept {
163 return !(lhs == rhs);
164 }
165
166 //! @}
167
168 /*! \name Basic
169 \brief Basic operations on complex numbers.
170 @{
171 */
172
173 //! Returns a new complex number with the given components.
174 SHZ_FORCE_INLINE complex cinitf(float real, float imag) noexcept {
175 return shz_cinitf(real, imag);
176 }
177
178 //! Converts the given polar coordinates into a complex number.
179 SHZ_FORCE_INLINE complex cpolarf(float r, float theta) noexcept {
180 return shz_cpolarf(r, theta);
181 }
182
183 //! Checks for relative equality between \p lhs and \p rhs.
184 SHZ_FORCE_INLINE bool cequalf(const complex& lhs, const complex& rhs) noexcept {
185 return shz_cequalf(lhs, rhs);
186 }
187
188 //! Returns the real component of the given complex number.
189 SHZ_FORCE_INLINE float crealf(const complex& c) noexcept {
190 return shz_crealf(c);
191 }
192
193 //! Returns the imaginary component of the given complex number.
194 SHZ_FORCE_INLINE float cimagf(const complex& c) noexcept {
195 return shz_cimagf(c);
196 }
197
198 //! @}
199
200 /*! \name Arithmetic
201 \brief Arithmetic operations on complex numbers.
202 @{
203 */
204
205 //! Adds the two complex numbers together, returning the complex result.
206 SHZ_FORCE_INLINE complex caddf(const complex& lhs, const complex& rhs) noexcept {
207 return shz_caddf(lhs, rhs);
208 }
209
210 //! Subtracts \p rhs from \p lhs, returning the complex result.
211 SHZ_FORCE_INLINE complex csubf(const complex& lhs, const complex& rhs) noexcept {
212 return shz_csubf(lhs, rhs);
213 }
214
215 //! Multiplies the two complex numbers together, returning the complex result.
216 SHZ_FORCE_INLINE complex cmulf(const complex& lhs, const complex& rhs) noexcept {
217 return shz_cmulf(lhs, rhs);
218 }
219
220 //! Divides \p lhs by \p rhs, returning the complex result.
221 SHZ_FORCE_INLINE complex cdivf(const complex& lhs, const complex& rhs) noexcept {
222 return shz_cdivf(lhs, rhs);
223 }
224
225 //! Multiplies \p lhs by the complex number created with \p v as its real component's value and no imaginary component value.
226 SHZ_FORCE_INLINE complex cscalef(const complex& lhs, float v) noexcept {
227 return shz_cscalef(lhs, v);
228 }
229
230 //! Returns the multiplicative reciprocal of the given complex number.
231 SHZ_FORCE_INLINE complex crecipf(const complex& c) noexcept {
232 return shz_crecipf(c);
233 }
234
235 //! @}
236
237 /*! \name Manipulation
238 \brief Extract or modify complex components.
239 @{
240 */
241
242 //! Returns the absolute value or magnitude of the given complex number.
243 SHZ_FORCE_INLINE float cabsf(const complex& c) noexcept {
244 return shz_cabsf(c);
245 }
246
247 //! Returns the inverse absolute value or magnitude of the given complex number.
248 SHZ_FORCE_INLINE float inv_cabsf(const complex& c) noexcept {
249 return shz_inv_cabsf(c);
250 }
251
252 //! Returns the squared magnitude of the given complex number.
253 SHZ_FORCE_INLINE float cnormf(const complex& c) noexcept {
254 return shz_cnormf(c);
255 }
256
257 //! Returns the phase angle of the given complex number.
258 SHZ_FORCE_INLINE float cargf(const complex& c) noexcept {
259 return shz_cargf(c);
260 }
261
262 //! Returns the complex conjugate of the given complex number.
263 SHZ_FORCE_INLINE complex conjf(const complex& c) noexcept {
264 return shz_conjf(c);
265 }
266
267 //! Returns the projection of the complex number onto the Riemann sphere.
268 SHZ_FORCE_INLINE complex cprojf(const complex& c) noexcept {
269 return shz_cprojf(c);
270 }
271
272 //! @}
273
274 /*! \name Transcendental
275 \brief Complex transcendental functions.
276 @{
277 */
278
279 //! Returns the complex square root of the given complex number.
280 SHZ_FORCE_INLINE complex csqrtf(const complex& c) noexcept {
281 return shz_csqrtf(c);
282 }
283
284 //! Raises a complex \p base to a complex power given by \p exp, returning a complex result.
285 SHZ_FORCE_INLINE complex cpowf(const complex& base, const complex& exp) noexcept {
286 return shz_cpowf(base, exp);
287 }
288
289 //! Returns the complex base `e` exponential of the given complex number.
290 SHZ_FORCE_INLINE complex cexpf(const complex& c) noexcept {
291 return shz_cexpf(c);
292 }
293
294 //! returns the complex natural logarithm of the given complex number.
295 SHZ_FORCE_INLINE complex clogf(const complex& c) noexcept {
296 return shz_clogf(c);
297 }
298
299 //! Returns the complex base 10 logarithm of the given complex number.
300 SHZ_FORCE_INLINE complex clog10f(const complex& c) noexcept {
301 return shz_clog10f(c);
302 }
303
304 //! @}
305
306 /*! \name Spherical Trigonometry
307 \brief Complex spherical trigonometric functions.
308 @{
309 */
310
311 //! Returns the sine of the given complex number.
312 SHZ_FORCE_INLINE complex csinf(const complex& c) noexcept {
313 return shz_csinf(c);
314 }
315
316 //! Returns the cosine of the given complex number.
317 SHZ_FORCE_INLINE complex ccosf(const complex& c) noexcept {
318 return shz_ccosf(c);
319 }
320
321 //! Returns the tangent of the given complex number.
322 SHZ_FORCE_INLINE complex ctanf(const complex& c) noexcept {
323 return shz_ctanf(c);
324 }
325
326 //! Returns the cosecant of the given complex number.
327 SHZ_FORCE_INLINE complex ccscf(const complex& c) noexcept {
328 return shz_ccscf(c);
329 }
330
331 //! Returns the secant of the given complex number.
332 SHZ_FORCE_INLINE complex csecf(const complex& c) noexcept {
333 return shz_csecf(c);
334 }
335
336 //! Returns the cotangent of the given complex number.
337 SHZ_FORCE_INLINE complex ccotf(const complex& c) noexcept {
338 return shz_ccotf(c);
339 }
340
341 //! Returns the arcsine of the given complex number.
342 SHZ_FORCE_INLINE complex casinf(const complex& c) noexcept {
343 return shz_casinf(c);
344 }
345
346 //! Returns the arccosine of the given complex number.
347 SHZ_FORCE_INLINE complex cacosf(const complex& c) noexcept {
348 return shz_cacosf(c);
349 }
350
351 //! Returns the arctangent of the given complex number.
352 SHZ_FORCE_INLINE complex catanf(const complex& c) noexcept {
353 return shz_catanf(c);
354 }
355
356 //! Returns the arccosecant of the given complex number.
357 SHZ_FORCE_INLINE complex cacscf(const complex& c) noexcept {
358 return shz_cacscf(c);
359 }
360
361 //! Returns the arcsecant of the given complex number.
362 SHZ_FORCE_INLINE complex casecf(const complex& c) noexcept {
363 return shz_casecf(c);
364 }
365
366 //! Returns the arccotangent of the given complex number.
367 SHZ_FORCE_INLINE complex cacotf(const complex& c) noexcept {
368 return shz_cacotf(c);
369 }
370
371 //! @}
372
373 /*! \name Hyperbolic Trigonometry
374 \brief Complex hyperbolic trigonometric functions.
375 @{
376 */
377
378 //! Returns the hyperbolic sine of the given complex number.
379 SHZ_FORCE_INLINE complex csinhf(const complex& c) noexcept {
380 return shz_csinhf(c);
381 }
382
383 //! Returns the hyperbolic cosine of the given complex number.
384 SHZ_FORCE_INLINE complex ccoshf(const complex& c) noexcept {
385 return shz_ccoshf(c);
386 }
387
388 //! Returns the hyperbolic tangent of the given complex number.
389 SHZ_FORCE_INLINE complex ctanhf(const complex& c) noexcept {
390 return shz_ctanhf(c);
391 }
392
393 //! Returns the hyperbolic cosecant of the given complex number.
394 SHZ_FORCE_INLINE complex ccschf(const complex& c) noexcept {
395 return shz_ccschf(c);
396 }
397
398 //! Returns the hyperbolic secant of the given complex number.
399 SHZ_FORCE_INLINE complex csechf(const complex& c) noexcept {
400 return shz_csechf(c);
401 }
402
403 //! Returns the hyperbolic cotangent of the given complex number.
404 SHZ_FORCE_INLINE complex ccothf(const complex& c) noexcept {
405 return shz_ccothf(c);
406 }
407
408 //! Returns the hyperbolic arcsine of the given complex number.
409 SHZ_FORCE_INLINE complex casinhf(const complex& c) noexcept {
410 return shz_casinhf(c);
411 }
412
413 //! Returns the hyperbolic arccosine of the given complex number.
414 SHZ_FORCE_INLINE complex cacoshf(const complex& c) noexcept {
415 return shz_cacoshf(c);
416 }
417
418 //! Returns the hyperbolic arctangent of the given complex number.
419 SHZ_FORCE_INLINE complex catanhf(const complex& c) noexcept {
420 return shz_catanhf(c);
421 }
422
423 //! Returns the hyperbolic arccosecant of the given complex number.
424 SHZ_FORCE_INLINE complex cacschf(const complex& c) noexcept {
425 return shz_cacschf(c);
426 }
427
428 //! Returns the hyperbolic arcsecant of the given complex number.
429 SHZ_FORCE_INLINE complex casechf(const complex& c) noexcept {
430 return shz_casechf(c);
431 }
432
433 //! Returns the hyperbolic arccotangent of the given complex number.
434 SHZ_FORCE_INLINE complex cacothf(const complex& c) noexcept {
435 return shz_cacothf(c);
436 }
437
438 //! @}
439
440 /*! \name Signal Processing
441 \brief Functions for processing complex signals.
442 @{
443 */
444
445 //! C++ wrapper around shz_fft(), which computes the FFT of the given buffer. \sa shz_fft()
446 SHZ_FORCE_INLINE void fft(shz_complex_t* s, size_t size) noexcept {
447 return shz_fft(s, size);
448 }
449
450 //! @}
451}
452
453#endif
Namespace enclosing the SH4ZAM C++ API.
Definition shz_cdefs.hpp:21
complex ctanf(const complex &c) noexcept
Returns the tangent of the given complex number.
complex ccscf(const complex &c) noexcept
Returns the cosecant of the given complex number.
float cargf(const complex &c) noexcept
Returns the phase angle of the given complex number.
complex cscalef(const complex &lhs, float v) noexcept
Multiplies lhs by the complex number created with v as its real component's value and no imaginary co...
complex cacosf(const complex &c) noexcept
Returns the arccosine of the given complex number.
complex csqrtf(const complex &c) noexcept
Returns the complex square root of the given complex number.
complex csechf(const complex &c) noexcept
Returns the hyperbolic secant of the given complex number.
bool operator!=(const complex &lhs, const complex &rhs) noexcept
Returns true if the two complex numbers are approximately inequal.
complex cexpf(const complex &c) noexcept
Returns the complex base e exponential of the given complex number.
complex operator/(const complex &lhs, const complex &rhs) noexcept
Divides lhs by rhs, returning the complex result.
complex conjf(const complex &c) noexcept
Returns the complex conjugate of the given complex number.
complex csecf(const complex &c) noexcept
Returns the secant of the given complex number.
complex clog10f(const complex &c) noexcept
Returns the complex base 10 logarithm of the given complex number.
complex cdivf(const complex &lhs, const complex &rhs) noexcept
Divides lhs by rhs, returning the complex result.
float cnormf(const complex &c) noexcept
Returns the squared magnitude of the given complex number.
complex casinhf(const complex &c) noexcept
Returns the hyperbolic arcsine of the given complex number.
complex cacoshf(const complex &c) noexcept
Returns the hyperbolic arccosine of the given complex number.
complex clogf(const complex &c) noexcept
returns the complex natural logarithm of the given complex number.
float inv_cabsf(const complex &c) noexcept
Returns the inverse absolute value or magnitude of the given complex number.
complex csubf(const complex &lhs, const complex &rhs) noexcept
Subtracts rhs from lhs, returning the complex result.
complex csinhf(const complex &c) noexcept
Returns the hyperbolic sine of the given complex number.
complex catanf(const complex &c) noexcept
Returns the arctangent of the given complex number.
complex cprojf(const complex &c) noexcept
Returns the projection of the complex number onto the Riemann sphere.
complex operator-(const complex &lhs, const complex &rhs) noexcept
Subtracts rhs from lhs, returning the complex result.
complex cacothf(const complex &c) noexcept
Returns the hyperbolic arccotangent of the given complex number.
complex casecf(const complex &c) noexcept
Returns the arcsecant of the given complex number.
complex ccosf(const complex &c) noexcept
Returns the cosine of the given complex number.
complex ccothf(const complex &c) noexcept
Returns the hyperbolic cotangent of the given complex number.
complex catanhf(const complex &c) noexcept
Returns the hyperbolic arctangent of the given complex number.
complex operator/(const complex &lhs, float rhs) noexcept
Divides lhs by a complex number with the real compoonent given as rhs and no imaginary component.
complex operator*(const complex &lhs, float rhs) noexcept
Multiplies lhs by a complex number with the real component given as rhs and no imaginary component.
complex caddf(const complex &lhs, const complex &rhs) noexcept
Adds the two complex numbers together, returning the complex result.
complex csinf(const complex &c) noexcept
Returns the sine of the given complex number.
float cabsf(const complex &c) noexcept
Returns the absolute value or magnitude of the given complex number.
complex cpolarf(float r, float theta) noexcept
Converts the given polar coordinates into a complex number.
float cimagf(const complex &c) noexcept
Returns the imaginary component of the given complex number.
complex cinitf(float real, float imag) noexcept
Returns a new complex number with the given components.
complex ccotf(const complex &c) noexcept
Returns the cotangent of the given complex number.
complex operator+(const complex &lhs, const complex &rhs) noexcept
Adds the two complex numbers, lhs and rhs, returning the result.
complex casechf(const complex &c) noexcept
Returns the hyperbolic arcsecant of the given complex number.
bool cequalf(const complex &lhs, const complex &rhs) noexcept
Checks for relative equality between lhs and rhs.
complex casinf(const complex &c) noexcept
Returns the arcsine of the given complex number.
complex cpowf(const complex &base, const complex &exp) noexcept
Raises a complex base to a complex power given by exp, returning a complex result.
complex ccschf(const complex &c) noexcept
Returns the hyperbolic cosecant of the given complex number.
float crealf(const complex &c) noexcept
Returns the real component of the given complex number.
complex crecipf(const complex &c) noexcept
Returns the multiplicative reciprocal of the given complex number.
complex cacscf(const complex &c) noexcept
Returns the arccosecant of the given complex number.
complex cacschf(const complex &c) noexcept
Returns the hyperbolic arccosecant of the given complex number.
complex ctanhf(const complex &c) noexcept
Returns the hyperbolic tangent of the given complex number.
complex operator*(const complex &lhs, const complex &rhs) noexcept
Multiplies lhs by rhs, returning the complex result.
complex cacotf(const complex &c) noexcept
Returns the arccotangent of the given complex number.
void fft(shz_complex_t *s, size_t size) noexcept
C++ wrapper around shz_fft(), which computes the FFT of the given buffer.
complex ccoshf(const complex &c) noexcept
Returns the hyperbolic cosine of the given complex number.
bool operator==(const complex &lhs, const complex &rhs) noexcept
Returns true if the two complex numbers are approximately equal.
complex cmulf(const complex &lhs, const complex &rhs) noexcept
Multiplies the two complex numbers together, returning the complex result.
float shz_inv_cabsf(shz_complex_t c) SHZ_NOEXCEPT
Returns the inverse of the absolute value (or inverse of the magnitude) of the complex number,...
shz_complex_t shz_cacoshf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arccosine of c.
shz_complex_t shz_ccotf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex cotangent of c.
shz_complex_t shz_cmulf(shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
Multiplies two complex numbers together, returning the complex result.
void shz_fft(shz_complex_t *s, size_t size) SHZ_NOEXCEPT
Fast Fourier Transform.
float shz_cimagf(shz_complex_t c) SHZ_NOEXCEPT
Returns the imaginary component of a complex number.
shz_complex_t shz_catanf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arctangent of c.
shz_complex_t shz_casinf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arcsine of c.
shz_complex_t shz_csinf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex sine of c.
shz_complex_t shz_csechf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic secant of c.
shz_complex_t shz_ccschf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic cosecant of c.
shz_complex_t shz_crecipf(shz_complex_t c) SHZ_NOEXCEPT
Returns the multiplicative inverse or reciprocal of the complex number, c.
float shz_cabsf(shz_complex_t c) SHZ_NOEXCEPT
Returns the absolute value (or magnitude) of the complex number, c.
shz_complex_t shz_cacothf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arccotangent of c.
shz_complex_t shz_ctanf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex tangent of c.
shz_complex_t shz_cscalef(shz_complex_t c, float v) SHZ_NOEXCEPT
Scales both componets of the complex number, c, by the value, v, returning the result.
shz_complex_t shz_cprojf(shz_complex_t c) SHZ_NOEXCEPT
Calculates the projection of the complex number, c, onto the Riemann sphere.
shz_complex_t shz_cdivf(shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
Divides lhs by rhs, returning the complex result.
shz_complex_t shz_csubf(shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
Subtracts rhs from lhs and returns the complex result.
shz_complex_t shz_casechf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arcsecant of c.
shz_complex_t shz_cacotf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arccotangent of c.
shz_complex_t shz_csqrtf(shz_complex_t c) SHZ_NOEXCEPT
Computes and returns the complex square root of c.
shz_complex_t shz_casinhf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arcsine of c.
bool shz_cequalf(shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
Checks for equality between two complex numbers with either an absolute or relative tolerance.
float shz_cnormf(shz_complex_t c) SHZ_NOEXCEPT
Returns the squared magnitude of the complex number, c.
shz_complex_t shz_caddf(shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
Adds two complex numbers together and returns the result.
shz_complex_t shz_casecf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arcsecant of c.
shz_complex_t shz_clogf(shz_complex_t c) SHZ_NOEXCEPT
Computes and returns the complex natural logarithm of c.
float shz_crealf(shz_complex_t c) SHZ_NOEXCEPT
Returns the real component of a complex number.
shz_complex_t shz_csecf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex secant of c.
shz_complex_t shz_cpolarf(float r, float theta) SHZ_NOEXCEPT
Returns a complex number with a magnitude of r, and a phase angle of theta (in radians).
shz_complex_t shz_ccoshf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic cosine of c.
shz_complex_t shz_cexpf(shz_complex_t c) SHZ_NOEXCEPT
Returns the complex base e exponential of c.
shz_complex_t shz_cinitf(float real, float imag) SHZ_NOEXCEPT
Returns a complex number which has been initialized to contain the given component values.
shz_complex_t shz_conjf(shz_complex_t c) SHZ_NOEXCEPT
Returns the complex conjugate of c.
shz_complex_t shz_catanhf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arctangent of c.
shz_complex_t shz_cpowf(shz_complex_t base, shz_complex_t exp) SHZ_NOEXCEPT
Raises the complex base to the complex exp power, returning a complex result.
shz_complex_t shz_cacschf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic arccosecant of c.
float shz_cargf(shz_complex_t c) SHZ_NOEXCEPT
Returns the phase angle of the complex number, c.
shz_complex_t shz_ccosf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex cosine of c.
shz_complex_t shz_ctanhf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic tangent of c.
shz_complex_t shz_cacosf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arccosine of c.
shz_complex_t shz_csinhf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic sine of c.
shz_complex_t shz_clog10f(shz_complex_t c) SHZ_NOEXCEPT
Computes and returns the complex base 10 logarithm of c.
shz_complex_t shz_ccothf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex hyperbolic cotangent of c.
shz_complex_t shz_cacscf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex arccosecant of c.
shz_complex_t shz_ccscf(shz_complex_t c) SHZ_NOEXCEPT
Calculates and returns the complex cosecant of c.
float shz_invf(float x) SHZ_NOEXCEPT
Takes the inverse of x using a slighty faster approximation than doing a full division,...
C++ wrapper around a floating-point complex number, real/imaginary pair.
complex & operator*=(float scale) noexcept
Multiplies and accumulates the given complex number by scalar.
complex(const volatile shz_complex_t &cplx) noexcept
Converting constructor for initialization from a volatile value type.
complex & operator/=(const complex &rhs) noexcept
Divides the given complex number by rhs, assigning it to the result.
complex(const complex &rhs) noexcept=default
Default copy constructor.
complex & operator+=(const complex &rhs) noexcept
Adds and accumulates rhs onto the given complex number.
complex(float re, float im=0.0f) noexcept
Value constructor, sets the imaginary component to 0 if none is supplied.
complex(const shz_complex_t &cplx) noexcept
Converting constructor for initializing from the C base type.
complex & operator*=(const complex &rhs) noexcept
Multiplies and accumulates rhs by the given complex number.
complex() noexcept=default
Default constructor.
complex & operator-=(const complex &rhs) noexcept
Subtracts rhs from the given complex number, assigning it to the result.
float real
The real portion of the complex number.
Definition shz_complex.h:48
float imag
The imaginary portion of the complex number.
Definition shz_complex.h:49