# Complex API

Source: https://sh4zam.com/api/complex/

> API for representing and operating on complex numbers, plus an SH4-optimized FFT

The complex number API serves as a replacement for C and C++'s `<complex.h>`, offering fast, accelerated approximations for each routine. The API is mostly modeled after C99's `<complex.h>`, although it also supports being used from C++ via `shz::complex`. The API also features `shz_fft()`, an SH4 optimized fast-fourier transform.

- **C header:** `#include <sh4zam/shz_complex.h>`
- **C++ header:** `#include <sh4zam/shz_complex.hpp>`
- **C++ types:** [`shz::complex`](https://sh4zam.com/api/cpp/complex/)
- **Symbols:** 52

## Suffixes

Suffixes used in this module. The full list is in [Naming and Suffixes](https://sh4zam.com/concepts/naming-and-suffixes/).

- `_fsrra`: Uses `FSRRA` (fast approximate 1/sqrt(x)). The argument or denominator must be positive. Faster, less precise.

## Preprocessor

Macros and preprocessor constants.

| Symbol | Description |
| --- | --- |
| [`SHZ_CMPLXF`](https://sh4zam.com/api/complex/SHZ_CMPLXF/) | Initializes a complex number. |
| [`SHZ_CMPLXF32`](https://sh4zam.com/api/complex/SHZ_CMPLXF32/) | Initializes a complex number. |
| [`SHZ_I`](https://sh4zam.com/api/complex/SHZ_I/) | Unit imaginary constant, 'I'. |

## Basic

Basic operations on complex numbers.

| Symbol | Description |
| --- | --- |
| [`shz_cinitf`](https://sh4zam.com/api/complex/shz_cinitf/) | Returns a complex number which has been initialized to contain the given component values. |
| [`shz_cpolarf`](https://sh4zam.com/api/complex/shz_cpolarf/) | Returns a complex number with a magnitude of `r`, and a phase angle of `theta` (in radians). |
| [`shz_cequalf`](https://sh4zam.com/api/complex/shz_cequalf/) | Checks for equality between two complex numbers with either an absolute or relative tolerance. |
| [`shz_crealf`](https://sh4zam.com/api/complex/shz_crealf/) | Returns the real component of a complex number. |
| [`shz_cimagf`](https://sh4zam.com/api/complex/shz_cimagf/) | Returns the imaginary component of a complex number. |

## Arithmetic

Arithmetic operations on complex numbers.

| Symbol | Description |
| --- | --- |
| [`shz_caddf`](https://sh4zam.com/api/complex/shz_caddf/) | Adds two complex numbers together and returns the result. |
| [`shz_csubf`](https://sh4zam.com/api/complex/shz_csubf/) | Subtracts `rhs` from `lhs` and returns the complex result. |
| [`shz_cmulf`](https://sh4zam.com/api/complex/shz_cmulf/) | Multiplies two complex numbers together, returning the complex result. |
| [`shz_cdivf`](https://sh4zam.com/api/complex/shz_cdivf/) | Divides `lhs` by `rhs`, returning the complex result. |
| [`shz_cscalef`](https://sh4zam.com/api/complex/shz_cscalef/) | Scales both componets of the complex number, `c`, by the value, `v`, returning the result. |
| [`shz_crecipf`](https://sh4zam.com/api/complex/shz_crecipf/) | Returns the multiplicative inverse or reciprocal of the complex number, `c`. |

## Manipulation

Extract or modify complex components.

| Symbol | Description |
| --- | --- |
| [`shz_cabsf`](https://sh4zam.com/api/complex/shz_cabsf/) | Returns the absolute value (or magnitude) of the complex number, `c`. |
| [`shz_inv_cabsf`](https://sh4zam.com/api/complex/shz_inv_cabsf/) | Returns the inverse of the absolute value (or inverse of the magnitude) of the complex number, `c`. |
| [`shz_cnormf`](https://sh4zam.com/api/complex/shz_cnormf/) | Returns the squared magnitude of the complex number, `c`. |
| [`shz_cargf`](https://sh4zam.com/api/complex/shz_cargf/) | Returns the phase angle of the complex number, `c`. |
| [`shz_conjf`](https://sh4zam.com/api/complex/shz_conjf/) | Returns the complex conjugate of `c`. |
| [`shz_cprojf`](https://sh4zam.com/api/complex/shz_cprojf/) | Calculates the projection of the complex number, `c`, onto the Riemann sphere. |

## Transcendental

Complex transcendental functions.

| Symbol | Description |
| --- | --- |
| [`shz_csqrtf`](https://sh4zam.com/api/complex/shz_csqrtf/) | Computes and returns the complex square root of `c`. |
| [`shz_cpowf`](https://sh4zam.com/api/complex/shz_cpowf/) | Raises the complex `base` to the complex `exp` power, returning a complex result. |
| [`shz_cexpf`](https://sh4zam.com/api/complex/shz_cexpf/) | Returns the complex base `e` exponential of `c`. |
| [`shz_clogf`](https://sh4zam.com/api/complex/shz_clogf/) | Computes and returns the complex natural logarithm of `c`. |
| [`shz_clog10f`](https://sh4zam.com/api/complex/shz_clog10f/) | Computes and returns the complex base 10 logarithm of `c`. |

## Spherical Trigonometry

Complex spherical trigonometric functions.

| Symbol | Description |
| --- | --- |
| [`shz_csinf`](https://sh4zam.com/api/complex/shz_csinf/) | Calculates and returns the complex sine of `c`. |
| [`shz_ccosf`](https://sh4zam.com/api/complex/shz_ccosf/) | Calculates and returns the complex cosine of `c`. |
| [`shz_ctanf`](https://sh4zam.com/api/complex/shz_ctanf/) | Calculates and returns the complex tangent of `c`. |
| [`shz_ccscf`](https://sh4zam.com/api/complex/shz_ccscf/) | Calculates and returns the complex cosecant of `c`. |
| [`shz_csecf`](https://sh4zam.com/api/complex/shz_csecf/) | Calculates and returns the complex secant of `c`. |
| [`shz_ccotf`](https://sh4zam.com/api/complex/shz_ccotf/) | Calculates and returns the complex cotangent of `c`. |
| [`shz_casinf`](https://sh4zam.com/api/complex/shz_casinf/) | Calculates and returns the complex arcsine of `c`. |
| [`shz_cacosf`](https://sh4zam.com/api/complex/shz_cacosf/) | Calculates and returns the complex arccosine of `c`. |
| [`shz_catanf`](https://sh4zam.com/api/complex/shz_catanf/) | Calculates and returns the complex arctangent of `c`. |
| [`shz_cacscf`](https://sh4zam.com/api/complex/shz_cacscf/) | Calculates and returns the complex arccosecant of `c`. |
| [`shz_casecf`](https://sh4zam.com/api/complex/shz_casecf/) | Calculates and returns the complex arcsecant of `c`. |
| [`shz_cacotf`](https://sh4zam.com/api/complex/shz_cacotf/) | Calculates and returns the complex arccotangent of `c`. |

## Hyperbolic Trigonometry

Complex hyperbolic trigonometric functions.

| Symbol | Description |
| --- | --- |
| [`shz_csinhf`](https://sh4zam.com/api/complex/shz_csinhf/) | Calculates and returns the complex hyperbolic sine of `c`. |
| [`shz_ccoshf`](https://sh4zam.com/api/complex/shz_ccoshf/) | Calculates and returns the complex hyperbolic cosine of `c`. |
| [`shz_ctanhf`](https://sh4zam.com/api/complex/shz_ctanhf/) | Calculates and returns the complex hyperbolic tangent of `c`. |
| [`shz_ccschf`](https://sh4zam.com/api/complex/shz_ccschf/) | Calculates and returns the complex hyperbolic cosecant of `c`. |
| [`shz_csechf`](https://sh4zam.com/api/complex/shz_csechf/) | Calculates and returns the complex hyperbolic secant of `c`. |
| [`shz_ccothf`](https://sh4zam.com/api/complex/shz_ccothf/) | Calculates and returns the complex hyperbolic cotangent of `c`. |
| [`shz_casinhf`](https://sh4zam.com/api/complex/shz_casinhf/) | Calculates and returns the complex hyperbolic arcsine of `c`. |
| [`shz_cacoshf`](https://sh4zam.com/api/complex/shz_cacoshf/) | Calculates and returns the complex hyperbolic arccosine of `c`. |
| [`shz_catanhf`](https://sh4zam.com/api/complex/shz_catanhf/) | Calculates and returns the complex hyperbolic arctangent of `c`. |
| [`shz_cacschf`](https://sh4zam.com/api/complex/shz_cacschf/) | Calculates and returns the complex hyperbolic arccosecant of `c`. |
| [`shz_casechf`](https://sh4zam.com/api/complex/shz_casechf/) | Calculates and returns the complex hyperbolic arcsecant of `c`. |
| [`shz_cacothf`](https://sh4zam.com/api/complex/shz_cacothf/) | Calculates and returns the complex hyperbolic arccotangent of `c`. |

## Signal Processing

Functions for processing complex signals.

| Symbol | Description |
| --- | --- |
| [`shz_fft`](https://sh4zam.com/api/complex/shz_fft/) | Fast Fourier Transform. |

## Types

| Symbol | Description |
| --- | --- |
| [`shz_complex_t`](https://sh4zam.com/api/complex/shz_complex_t/) | Represents a floating-point complex number real/imaginary pair. |
| [`shz_complex`](https://sh4zam.com/api/complex/shz_complex/) | [`shz_complex_t`](https://sh4zam.com/api/complex/shz_complex_t/) alias for those who don't like POSIX-style. |
