SH4ZAM! 0.1.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_complex.h File Reference
#include "shz_cdefs.h"
#include <stddef.h>
#include <stdbool.h>
#include "inline/shz_complex.inl.h"
Include dependency graph for shz_complex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  shz_complex_t
 

Macros

Preprocessor

Macros and preprocessor constants.

#define SHZ_CMPLXF(x, y)
 
#define SHZ_CMPLXF32(x, y)
 
#define SHZ_I
 

Typedefs

typedef shz_complex_t shz_complex
 

Functions

Basic

Basic operations on complex numbers.

shz_complex_t shz_cinitf (float real, float imag) SHZ_NOEXCEPT
 
shz_complex_t shz_cpolarf (float r, float theta) SHZ_NOEXCEPT
 
bool shz_cequalf (shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
 
float shz_crealf (shz_complex_t c) SHZ_NOEXCEPT
 
float shz_cimagf (shz_complex_t c) SHZ_NOEXCEPT
 
Arithmetic

Arithmetic operations on complex numbers.

shz_complex_t shz_caddf (shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
 
shz_complex_t shz_csubf (shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
 
shz_complex_t shz_cmulf (shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
 
shz_complex_t shz_cdivf (shz_complex_t lhs, shz_complex_t rhs) SHZ_NOEXCEPT
 
shz_complex_t shz_cscalef (shz_complex_t c, float v) SHZ_NOEXCEPT
 
shz_complex_t shz_crecipf (shz_complex_t c) SHZ_NOEXCEPT
 
Manipulation

Extract or modify complex components.

float shz_cabsf (shz_complex_t c) SHZ_NOEXCEPT
 
float shz_inv_cabsf (shz_complex_t c) SHZ_NOEXCEPT
 
float shz_cnormf (shz_complex_t c) SHZ_NOEXCEPT
 
float shz_cargf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_conjf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cprojf (shz_complex_t c) SHZ_NOEXCEPT
 
Transcendental

Complex transcendental functions.

shz_complex_t shz_csqrtf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cpowf (shz_complex_t base, shz_complex_t exp) SHZ_NOEXCEPT
 
shz_complex_t shz_cexpf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_clogf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_clog10f (shz_complex_t c) SHZ_NOEXCEPT
 
Spherical Trigonometry

Complex spherical trigonometric functions.

shz_complex_t shz_csinf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccosf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ctanf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccscf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_csecf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccotf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_casinf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacosf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_catanf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacscf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_casecf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacotf (shz_complex_t c) SHZ_NOEXCEPT
 
Hyperbolic Trigonometry

Complex hyperbolic trigonometric functions.

shz_complex_t shz_csinhf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccoshf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ctanhf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccschf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_csechf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_ccothf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_casinhf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacoshf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_catanhf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacschf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_casechf (shz_complex_t c) SHZ_NOEXCEPT
 
shz_complex_t shz_cacothf (shz_complex_t c) SHZ_NOEXCEPT
 
Signal Processing

Functions for processing complex signals.

void shz_fft (shz_complex_t *s, size_t size) SHZ_NOEXCEPT
 

Detailed Description

Complex number API.

This file contains a collection of routines for working with complex (real + imaginary) numbers. The API is mostly modeled after C99's <complex.h>, although it also supports being used from C++ as well.

Author
2026 Falco Girgis
Todo
  • to/from shz_mat2x2_t and XMTRX
  • FFT utilities
  • inverse FFT

Definition in file shz_complex.h.

Macro Definition Documentation

◆ SHZ_CMPLXF

#define SHZ_CMPLXF ( x,
y )

Initializes a complex number.

Definition at line 38 of file shz_complex.h.

◆ SHZ_CMPLXF32

#define SHZ_CMPLXF32 ( x,
y )

Initializes a complex number.

Definition at line 39 of file shz_complex.h.

◆ SHZ_I

#define SHZ_I

Unit imaginary constant, 'I'.

Definition at line 40 of file shz_complex.h.

Typedef Documentation

◆ shz_complex

shz_complex_t alias for those who don't like POSIX-style.

Definition at line 53 of file shz_complex.h.

Function Documentation

◆ shz_cinitf()

shz_complex_t shz_cinitf ( float real,
float imag )

Returns a complex number which has been initialized to contain the given component values.

◆ shz_cpolarf()

shz_complex_t shz_cpolarf ( float r,
float theta )

Returns a complex number with a magnitude of r, and a phase angle of theta (in radians).

◆ shz_cequalf()

bool shz_cequalf ( shz_complex_t lhs,
shz_complex_t rhs )

Checks for equality between two complex numbers with either an absolute or relative tolerance.

◆ shz_crealf()

float shz_crealf ( shz_complex_t c)

Returns the real component of a complex number.

◆ shz_cimagf()

float shz_cimagf ( shz_complex_t c)

Returns the imaginary component of a complex number.

◆ shz_caddf()

shz_complex_t shz_caddf ( shz_complex_t lhs,
shz_complex_t rhs )

Adds two complex numbers together and returns the result.

◆ shz_csubf()

shz_complex_t shz_csubf ( shz_complex_t lhs,
shz_complex_t rhs )

Subtracts rhs from lhs and returns the complex result.

◆ shz_cmulf()

shz_complex_t shz_cmulf ( shz_complex_t lhs,
shz_complex_t rhs )

Multiplies two complex numbers together, returning the complex result.

◆ shz_cdivf()

shz_complex_t shz_cdivf ( shz_complex_t lhs,
shz_complex_t rhs )

Divides lhs by rhs, returning the complex result.

◆ shz_cscalef()

shz_complex_t shz_cscalef ( shz_complex_t c,
float v )

Scales both componets of the complex number, c, by the value, v, returning the result.

◆ shz_crecipf()

shz_complex_t shz_crecipf ( shz_complex_t c)

Returns the multiplicative inverse or reciprocal of the complex number, c.

◆ shz_cabsf()

float shz_cabsf ( shz_complex_t c)

Returns the absolute value (or magnitude) of the complex number, c.

◆ shz_inv_cabsf()

float shz_inv_cabsf ( shz_complex_t c)

Returns the inverse of the absolute value (or inverse of the magnitude) of the complex number, c.

◆ shz_cnormf()

float shz_cnormf ( shz_complex_t c)

Returns the squared magnitude of the complex number, c.

◆ shz_cargf()

float shz_cargf ( shz_complex_t c)

Returns the phase angle of the complex number, c.

◆ shz_conjf()

shz_complex_t shz_conjf ( shz_complex_t c)

Returns the complex conjugate of c.

◆ shz_cprojf()

shz_complex_t shz_cprojf ( shz_complex_t c)

Calculates the projection of the complex number, c, onto the Riemann sphere.

◆ shz_csqrtf()

shz_complex_t shz_csqrtf ( shz_complex_t c)

Computes and returns the complex square root of c.

◆ shz_cpowf()

shz_complex_t shz_cpowf ( shz_complex_t base,
shz_complex_t exp )

Raises the complex base to the complex exp power, returning a complex result.

◆ shz_cexpf()

shz_complex_t shz_cexpf ( shz_complex_t c)

Returns the complex base e exponential of c.

◆ shz_clogf()

shz_complex_t shz_clogf ( shz_complex_t c)

Computes and returns the complex natural logarithm of c.

◆ shz_clog10f()

shz_complex_t shz_clog10f ( shz_complex_t c)

Computes and returns the complex base 10 logarithm of c.

◆ shz_csinf()

shz_complex_t shz_csinf ( shz_complex_t c)

Calculates and returns the complex sine of c.

◆ shz_ccosf()

shz_complex_t shz_ccosf ( shz_complex_t c)

Calculates and returns the complex cosine of c.

◆ shz_ctanf()

shz_complex_t shz_ctanf ( shz_complex_t c)

Calculates and returns the complex tangent of c.

◆ shz_ccscf()

shz_complex_t shz_ccscf ( shz_complex_t c)

Calculates and returns the complex cosecant of c.

◆ shz_csecf()

shz_complex_t shz_csecf ( shz_complex_t c)

Calculates and returns the complex secant of c.

◆ shz_ccotf()

shz_complex_t shz_ccotf ( shz_complex_t c)

Calculates and returns the complex cotangent of c.

◆ shz_casinf()

shz_complex_t shz_casinf ( shz_complex_t c)

Calculates and returns the complex arcsine of c.

◆ shz_cacosf()

shz_complex_t shz_cacosf ( shz_complex_t c)

Calculates and returns the complex arccosine of c.

◆ shz_catanf()

shz_complex_t shz_catanf ( shz_complex_t c)

Calculates and returns the complex arctangent of c.

◆ shz_cacscf()

shz_complex_t shz_cacscf ( shz_complex_t c)

Calculates and returns the complex arccosecant of c.

◆ shz_casecf()

shz_complex_t shz_casecf ( shz_complex_t c)

Calculates and returns the complex arcsecant of c.

◆ shz_cacotf()

shz_complex_t shz_cacotf ( shz_complex_t c)

Calculates and returns the complex arccotangent of c.

◆ shz_csinhf()

shz_complex_t shz_csinhf ( shz_complex_t c)

Calculates and returns the complex hyperbolic sine of c.

◆ shz_ccoshf()

shz_complex_t shz_ccoshf ( shz_complex_t c)

Calculates and returns the complex hyperbolic cosine of c.

◆ shz_ctanhf()

shz_complex_t shz_ctanhf ( shz_complex_t c)

Calculates and returns the complex hyperbolic tangent of c.

◆ shz_ccschf()

shz_complex_t shz_ccschf ( shz_complex_t c)

Calculates and returns the complex hyperbolic cosecant of c.

◆ shz_csechf()

shz_complex_t shz_csechf ( shz_complex_t c)

Calculates and returns the complex hyperbolic secant of c.

◆ shz_ccothf()

shz_complex_t shz_ccothf ( shz_complex_t c)

Calculates and returns the complex hyperbolic cotangent of c.

◆ shz_casinhf()

shz_complex_t shz_casinhf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arcsine of c.

◆ shz_cacoshf()

shz_complex_t shz_cacoshf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arccosine of c.

◆ shz_catanhf()

shz_complex_t shz_catanhf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arctangent of c.

◆ shz_cacschf()

shz_complex_t shz_cacschf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arccosecant of c.

◆ shz_casechf()

shz_complex_t shz_casechf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arcsecant of c.

◆ shz_cacothf()

shz_complex_t shz_cacothf ( shz_complex_t c)

Calculates and returns the complex hyperbolic arccotangent of c.

◆ shz_fft()

void shz_fft ( shz_complex_t * s,
size_t size )

Fast Fourier Transform.

Applies a fast fourier transform to convert the complex array of samples, s, of the given size, from the time to the frequency domain. The conversion is done in-place.

Note
The underlying implementation uses the Radix2 variant of the Cooley-Tukey FFT algorithm, using an XMTRX-accelerated 2 point butterfly DIF.
Warning
size must be a power-of-two!
This routine clobbers XMTRX!