Skip to content

Trigonometry API

Markdown

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 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 native FSCA input format.
  • _fsrra: Uses FSRRA (fast approximate 1/sqrt(x)). The argument or denominator must be positive. Faster, less precise.

Routines involving precomputed sine + cosine pairs.

SymbolDescription
shz_sincosu16Returns sinf()/cosf() pairs for the given unsigned 16-bit angle in radians.
shz_sincosfReturns sinf()/cosf() pairs for the given floating-point angle in radians.
shz_sincosf_degReturns sinf/cosf() pairs for the given floating-point angle in degrees.
shz_sincos_tanfReturns tanf() from the given pre-computed sincos pair.
shz_sincos_secfReturns the floating-point secant (1.0f / cosf(x)) from the given pre-computed sincos pair.
shz_sincos_cscfReturns the floating-point cosecant (1.0f / sinf(x)) from the given pre-computed sincos pair.
shz_sincos_cotfReturns the floating-point cotangent (1.0f / tanf(x)) from the given pre-computed sincos pair.

Routines providing single trigonometric functions.

SymbolDescription
shz_sinfOne-off routine for returning only sinf() from an angle in radians.
shz_sinf_degOne-off routine for returning only sinf() from an angle in degrees.
shz_cosfOne-off routine for returning only cosf() from an angle in radians.
shz_cosf_degOne-off routine for returning only cosf() from an angle in degrees.
shz_tanfOne-off routine for returning only tanf() from an angle in radians.
shz_tanf_degOne-off routine for returning only tanf() from an angle in degrees.
shz_secfOne-off routine for returning only secant (1 / cos(x)) from an angle in radians.
shz_secf_degOne-off routine for returning only secant (1 / cos(x)) from an angle in degrees.
shz_cscfOne-off routine for returning only cosecant (1 / sin(x)) from an angle in radians.
shz_cscf_degOne-off routine for returning only cosecant (1 / sin(x)) from an angle in degrees.
shz_cotfOne-off routine for returning only cotangent (1 / tan(x)) from an angle in radians.
shz_cotf_degOne-off routine for returning only cotangent (1 / cot(x)) from an angle in degrees.

Routines providing inverse trigonometric functions.

SymbolDescription
shz_asinfFast arcsine approximation; equivalent to C's asinf().
shz_acosfFast arccosine approximation; equivalent to C's acosf().
shz_atanf_unitFast arctangent approximation for unit values between 0.0f and 1.0f.
shz_atanf_q1Fast arctangent approximation for values lying within the first quadrant (>= 0.0f).
shz_atanfFast arctangent approximation; equvalent to C's atanf().
shz_atan2fComputes arctangent of y / x, using the signs of arguments to determine correct quadtrant. Equivalent to C's atan2f().
shz_asecfFast arcsecant/inverse secant approximation, taking units in radians.
shz_acscfFast arccosecant/inverse cosecant approximation; taking units in radians.
shz_acotfFast arccotangent/inverse cotangent approximation; taking units in radians.

Trigonometric functions for hyperbolas

SymbolDescription
shz_sinhfFast hyperbolic sine function.
shz_coshfFast hyperbolic cosine function.
shz_tanhfFast hyperbolic tangent function.
shz_cschfFast hyperbolic cosecant function.
shz_sechfFast hyperbolic secant function.
shz_cothfFast hyperbolic cotangent function.

Inverse trigonometric functions for hyperbolas

SymbolDescription
shz_asinhfFast hyperbolic arcsine function.
shz_acoshfFast hyperbolic arccosine function.
shz_atanhfFast hyperbolic arctangent function.
shz_acschfFast hyperbolic arccosecant function.
shz_asechfFast hyperbolic arcsecant function.
shz_acothfFast hyperbolic arccotangent function.
SymbolDescription
SHZ_F_PISingle-precision floating-point PI approximation (do not use M_PI!).
SHZ_F_TAUSingle-precision FP PI approximation times 2.
SHZ_F_PI_2Single-precision FP PI approximation divided by 2.
SHZ_F_PI_4Single-precision FP PI approximation divided by 4.
SHZ_FSCA_RAD_FACTORMultiplicative factor for passing the FSCA instruction angles in radians.
SHZ_FSCA_DEG_FACTORMultiplicative factor for passing the FSCA instrution angles in degrees.
SHZ_FSCA_ERROR_MAXMaximum FP error for FSCA instruction.
SHZ_DEG_TO_RADConverts the given angle in degrees to radians.
SHZ_RAD_TO_DEGConverts the given angle in radians to degrees.
SymbolDescription
shz_sincos_tPair representing the sine and cosine of a given angle.
shz_sincosAlternate C shz_sincos_t typedef for those who hate POSIX style.