Trigonometry API
The following API provides a series of routines implementing trigonometric functions. While some of these are specialized, many are meant to be drop-in replacements for the equivalent functions provided by <math.h>. The SH4 provides a single instruction, FSCA, for retrieving fast approximations of both the sine and cosine of a given angle, so when you need both values it is most efficient to grab them at once as a shz_sincos_t pair. Angles are in radians by default; _deg variants take degrees and u16 variants take the 16-bit fixed-point angle that FSCA consumes natively.
- C header:
#include <sh4zam/shz_trig.h> - C++ header:
#include <sh4zam/shz_trig.hpp> - C++ types:
shz::sincos - Symbols: 51
Suffixes
Section titled “Suffixes”Suffixes used in this module. The full list is in Naming and Suffixes.
_deg: Angle argument is in degrees. The default is radians.u16: Angle is a 16-bit fixed-point value: 0..65535 maps to 0..2π, the nativeFSCAinput format._fsrra: UsesFSRRA(fast approximate 1/sqrt(x)). The argument or denominator must be positive. Faster, less precise.
Sin/Cos Pairs
Section titled “Sin/Cos Pairs”Routines involving precomputed sine + cosine pairs.
| Symbol | Description |
|---|---|
shz_sincosu16 | Returns sinf()/cosf() pairs for the given unsigned 16-bit angle in radians. |
shz_sincosf | Returns sinf()/cosf() pairs for the given floating-point angle in radians. |
shz_sincosf_deg | Returns sinf/cosf() pairs for the given floating-point angle in degrees. |
shz_sincos_tanf | Returns tanf() from the given pre-computed sincos pair. |
shz_sincos_secf | Returns the floating-point secant (1.0f / cosf(x)) from the given pre-computed sincos pair. |
shz_sincos_cscf | Returns the floating-point cosecant (1.0f / sinf(x)) from the given pre-computed sincos pair. |
shz_sincos_cotf | Returns the floating-point cotangent (1.0f / tanf(x)) from the given pre-computed sincos pair. |
Independent Functions
Section titled “Independent Functions”Routines providing single trigonometric functions.
| Symbol | Description |
|---|---|
shz_sinf | One-off routine for returning only sinf() from an angle in radians. |
shz_sinf_deg | One-off routine for returning only sinf() from an angle in degrees. |
shz_cosf | One-off routine for returning only cosf() from an angle in radians. |
shz_cosf_deg | One-off routine for returning only cosf() from an angle in degrees. |
shz_tanf | One-off routine for returning only tanf() from an angle in radians. |
shz_tanf_deg | One-off routine for returning only tanf() from an angle in degrees. |
shz_secf | One-off routine for returning only secant (1 / cos(x)) from an angle in radians. |
shz_secf_deg | One-off routine for returning only secant (1 / cos(x)) from an angle in degrees. |
shz_cscf | One-off routine for returning only cosecant (1 / sin(x)) from an angle in radians. |
shz_cscf_deg | One-off routine for returning only cosecant (1 / sin(x)) from an angle in degrees. |
shz_cotf | One-off routine for returning only cotangent (1 / tan(x)) from an angle in radians. |
shz_cotf_deg | One-off routine for returning only cotangent (1 / cot(x)) from an angle in degrees. |
Inverse Functions
Section titled “Inverse Functions”Routines providing inverse trigonometric functions.
| Symbol | Description |
|---|---|
shz_asinf | Fast arcsine approximation; equivalent to C's asinf(). |
shz_acosf | Fast arccosine approximation; equivalent to C's acosf(). |
shz_atanf_unit | Fast arctangent approximation for unit values between 0.0f and 1.0f. |
shz_atanf_q1 | Fast arctangent approximation for values lying within the first quadrant (>= 0.0f). |
shz_atanf | Fast arctangent approximation; equvalent to C's atanf(). |
shz_atan2f | Computes arctangent of y / x, using the signs of arguments to determine correct quadtrant. Equivalent to C's atan2f(). |
shz_asecf | Fast arcsecant/inverse secant approximation, taking units in radians. |
shz_acscf | Fast arccosecant/inverse cosecant approximation; taking units in radians. |
shz_acotf | Fast arccotangent/inverse cotangent approximation; taking units in radians. |
Hyperbolic Functions
Section titled “Hyperbolic Functions”Trigonometric functions for hyperbolas
| Symbol | Description |
|---|---|
shz_sinhf | Fast hyperbolic sine function. |
shz_coshf | Fast hyperbolic cosine function. |
shz_tanhf | Fast hyperbolic tangent function. |
shz_cschf | Fast hyperbolic cosecant function. |
shz_sechf | Fast hyperbolic secant function. |
shz_cothf | Fast hyperbolic cotangent function. |
Inverse Hyperbolic Functions
Section titled “Inverse Hyperbolic Functions”Inverse trigonometric functions for hyperbolas
| Symbol | Description |
|---|---|
shz_asinhf | Fast hyperbolic arcsine function. |
shz_acoshf | Fast hyperbolic arccosine function. |
shz_atanhf | Fast hyperbolic arctangent function. |
shz_acschf | Fast hyperbolic arccosecant function. |
shz_asechf | Fast hyperbolic arcsecant function. |
shz_acothf | Fast hyperbolic arccotangent function. |
Macros
Section titled “Macros”| Symbol | Description |
|---|---|
SHZ_F_PI | Single-precision floating-point PI approximation (do not use M_PI!). |
SHZ_F_TAU | Single-precision FP PI approximation times 2. |
SHZ_F_PI_2 | Single-precision FP PI approximation divided by 2. |
SHZ_F_PI_4 | Single-precision FP PI approximation divided by 4. |
SHZ_FSCA_RAD_FACTOR | Multiplicative factor for passing the FSCA instruction angles in radians. |
SHZ_FSCA_DEG_FACTOR | Multiplicative factor for passing the FSCA instrution angles in degrees. |
SHZ_FSCA_ERROR_MAX | Maximum FP error for FSCA instruction. |
SHZ_DEG_TO_RAD | Converts the given angle in degrees to radians. |
SHZ_RAD_TO_DEG | Converts the given angle in radians to degrees. |
| Symbol | Description |
|---|---|
shz_sincos_t | Pair representing the sine and cosine of a given angle. |
shz_sincos | Alternate C shz_sincos_t typedef for those who hate POSIX style. |