Skip to content

C++ API

Markdown

C++ code can still use the C API by design, and every C++ type is also compatible with its corresponding C types and C API, so you can mix and match.

Include <sh4zam/shz_sh4zam.hpp> (or a per-module .hpp). Vector, quaternion and matrix types derive from the C structs and add methods and operators; shz::xmtrx exposes the active matrix as static member functions; scalar and trig routines are constexpr aliases of the C functions with the shz_ prefix dropped.

ClassC typeHeaderDescription
shz::vecNn/ash4zam/shz_vector.hppCommon C++ base structure inherited by all vector types.
shz::vec2shz_vec2_tsh4zam/shz_vector.hpp2D Vector type
shz::vec3shz_vec3_tsh4zam/shz_vector.hpp3D Vector type
shz::vec4shz_vec4_tsh4zam/shz_vector.hpp4D Vector type
shz::quatshz_quat_tsh4zam/shz_quat.hppC++ structure representing a quaternion.
shz::mat4x4shz_mat4x4_tsh4zam/shz_matrix.hpp
shz::xmtrxn/ash4zam/shz_xmtrx.hppStatic structure around the 4x4 XMTRX FP register back-bank.
shz::sincosshz_sincos_tsh4zam/shz_trig.hppC++ sine/cosine approximation pairs.
shz::complexshz_complex_tsh4zam/shz_complex.hppC++ wrapper around a floating-point complex number, real/imaginary pair.
shz::versionn/ash4zam/shz_version.hppClass representing a full SH4ZAM API version.
C++C functionDescription
shz::pow2fshz_pow2fFast approximation for raising 2 to a floating-point power.
shz::powfshz_powfFast approximation for C's powf().
shz::powifshz_powifRaises x to the integer power n, using exponentiation by squaring.
shz::pow10fshz_pow10fFast approximation of POSIX's pow10f().
shz::log2fshz_log2fFast approximation for C's log2f().
shz::logfshz_logfFast approximation for C's logf().
shz::log10fshz_log10fFast approximation for C's log10f().
shz::expfshz_expfFast approximation for C's expf().
shz::expm1fshz_expm1fFast approximation for C's expm1f().
shz::log1pfshz_log1pfFast approximation for C's log1pf().
shz::logbfshz_logbfFast approximation for C's logbf().
shz::ldexpfshz_ldexpfFast approximation for C's ldexpf(), taking a floating-point exponent.
shz::scalbnfshz_scalbnfFast approximation for C's scalbnf(), taking a floating-point exponent.
shz::erffshz_erffFast approximation for C's erff().
shz::fminfshz_fminfReturns the minimum value of two given floats.
shz::fmaxfshz_fmaxfReturns the maximum value of two given floats.
shz::equalfshz_equalfChecks for equality based on EITHER the absolute tolerance or relative tolerance, using SHZ_FLT_EPSILON.
shz::equalf_absshz_equalf_absChecks for equality based on the absolute tolerance using SHZ_FLT_EPSILON.
shz::equalf_relshz_equalf_relChecks for equality based on the relative tolerance using SHZ_FLT_EPSILON.
shz::floorfshz_floorfReplacement for the <math.h> routine, floorf().
shz::ceilfshz_ceilfReplacement for the <math.h> routine, ceilf().
shz::roundfshz_roundfReplacement for the <math.h> routine, roundf().
shz::truncfshz_truncfReplacement for the <math.h> routine, truncf().
shz::remainderfshz_remainderfReplacement for the <math.h> routine, remainderf().
shz::fmodfshz_fmodfReplacement for the <math.h> routine, fmodf().
shz::remquofshz_remquof(Sorta) Replacement for the <math.h> routine, remquof().
shz::clampfshz_clampfClamps a floating-point value by the given min and max values.
shz::normalizefshz_normalizefMaps a value within the given range from to to, to be within the range of 0.0f to 1.0f. Returns 1.0f when from == to.
shz::normalizef_fsrrashz_normalizef_fsrraMaps a value within the given range from to to, to be within the range of 0.0f to 1.0f more quickly, provided to - from is a positive difference.
shz::remapfshz_remapfMaps a value within the given range inputStart to inputEnd, to be within the range of outputStart to outputEnd.
shz::remapf_fsrrashz_remapf_fsrraMaps a value within the given range inputStart to inputEnd, to be within the range of outputStart to outputEnd more quickly, provided inputEnd - inputStart is a positive difference.
shz::wrapfshz_wrapfWraps the given value back to be within the range of min to max.
shz::wrapf_fsrrashz_wrapf_fsrraWraps the given value back to be within the range of min to max more quickly, provided max - min is a positive difference.
shz::fractfshz_fractfReturns the fractional part of x, equivalent to GLSL fract().
shz::signfshz_signfReturns -1.0f if x < 0, 0.0f if x == 0, or 1.0f if x > 0.
shz::saturatefshz_saturatefClamps x to the range [0.0f, 1.0f].
shz::fabsfshz_fabsfReplacement for the <math.h> routine, fabsf().
shz::copysignfshz_copysignfReplacement for the <math.h> routine, copysignf().
shz::fmafshz_fmafReplacement for the <math.h> routine, fmaf().
shz::opaquefshz_opaquefReturns value unchanged, hidden from the optimizer.
shz::fdimfshz_fdimfReplacement for the <math.h> routine, fdimf(),.
shz::hypotfshz_hypotfReplacement for the <math.h> routine, hypotf().
shz::cbrtfshz_cbrtfReplacement for the <math.h> routine, cbrtf().
shz::lerpfshz_lerpfReturns a value that is linearly interpolated between a and b by the given ratio, t.
shz::barycentric_lerpfshz_barycentric_lerpfReturns a value that is barycentrically interpolated between a, b, and c using the given barycentric coordinates, u and v.
shz::quadratic_rootsshz_quadratic_rootsUses the quadratic formula with the given coefficients to solve for the two roots, returning true if any real roots exist, and false if the roots are only imaginary.
shz::randfshz_randfReturns a random floating-point number between 0.0f and 1.0f, using and updating the given seed.
shz::randf_rangeshz_randf_rangeReturns a random floating-point number between min and max, using and updating the given seed.
shz::stepfshz_stepfReturns 0.0f if x < edge, otherwise 1.0f.
shz::smoothstepfshz_smoothstepfReturns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between. edge0 must be less than edge1 or result is undefined.
shz::smoothstepf_safeshz_smoothstepf_safeReturns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between. Accepts inverse edges.
shz::inv_sqrtf_fsrrashz_inv_sqrtf_fsrraCalculates 1.0f/sqrtf( x), using a fast approximation.
shz::inv_sqrtfshz_inv_sqrtfCalculates 1.0f/sqrtf( x ), using a fast approximation, while safely protecting against division-by-zero.
shz::sqrtf_fsrrashz_sqrtf_fsrraReturns the fast approximate square root of the given value, x.
shz::sqrtf_fsrra_safeshz_sqrtf_fsrra_safeReturns the fast approximate square root of the given value, x, using FSRRA, safely returning 0.0f if x == 0.0f.
shz::sqrtfshz_sqrtfReturns the fast approximate square root of the given value, x, safely returning 0.0f is x == 0.0f.
shz::invf_fsrrashz_invf_fsrraFast unsigned approximate inverse of a number.
shz::invfshz_invfApproximate inverse of a signed number.
shz::divf_fsrrashz_divf_fsrraFast approximate division by an unsigned denominator.
shz::divfshz_divfApproximate division by a signed denominator.
shz::dot6fshz_dot6fTakes two sets of 3D vectors as 3 floats and calculates their dot product using an approximation.
shz::dot8fshz_dot8fTakes two sets of 4D vectors as 4 floats and calculates their dot product using an approximation.
shz::mag_sqr3fshz_mag_sqr3fTakes a 3D vector as 3 floats and calculates its squared magnitude using a fast approximation.
shz::mag_sqr4fshz_mag_sqr4fTakes a 4D vector as 4 floats and calculates its squared magnitude using a fast approximation.
shz::operator/shz_invfApproximate inverse of a signed number.
shz::operator/shz_invfApproximate inverse of a signed number.
C++C functionDescription
shz::sincosu16shz_sincosu16Returns sinf()/cosf() pairs for the given unsigned 16-bit angle in radians.
shz::sincosfshz_sincosfReturns sinf()/cosf() pairs for the given floating-point angle in radians.
shz::sincosf_degshz_sincosf_degReturns sinf/cosf() pairs for the given floating-point angle in degrees.
shz::sincos_tanfshz_sincos_tanfReturns tanf() from the given pre-computed sincos pair.
shz::sincos_secfshz_sincos_secfReturns the floating-point secant (1.0f / cosf(x)) from the given pre-computed sincos pair.
shz::sincos_cscfshz_sincos_cscfReturns the floating-point cosecant (1.0f / sinf(x)) from the given pre-computed sincos pair.
shz::sincos_cotfshz_sincos_cotfReturns the floating-point cotangent (1.0f / tanf(x)) from the given pre-computed sincos pair.
shz::sinfshz_sinfOne-off routine for returning only sinf() from an angle in radians.
shz::sinf_degshz_sinf_degOne-off routine for returning only sinf() from an angle in degrees.
shz::cosfshz_cosfOne-off routine for returning only cosf() from an angle in radians.
shz::cosf_degshz_cosf_degOne-off routine for returning only cosf() from an angle in degrees.
shz::tanfshz_tanfOne-off routine for returning only tanf() from an angle in radians.
shz::tanf_degshz_tanf_degOne-off routine for returning only tanf() from an angle in degrees.
shz::secfshz_secfOne-off routine for returning only secant (1 / cos(x)) from an angle in radians.
shz::secf_degshz_secf_degOne-off routine for returning only secant (1 / cos(x)) from an angle in degrees.
shz::cscfshz_cscfOne-off routine for returning only cosecant (1 / sin(x)) from an angle in radians.
shz::cscf_degshz_cscf_degOne-off routine for returning only cosecant (1 / sin(x)) from an angle in degrees.
shz::cotfshz_cotfOne-off routine for returning only cotangent (1 / tan(x)) from an angle in radians.
shz::cotf_degshz_cotf_degOne-off routine for returning only cotangent (1 / cot(x)) from an angle in degrees.
shz::atanf_unitshz_atanf_unitFast arctangent approximation for unit values between 0.0f and 1.0f.
shz::atanf_q1shz_atanf_q1Fast arctangent approximation for values lying within the first quadrant (>= 0.0f).
shz::atanfshz_atanfFast arctangent approximation; equvalent to C's atanf().
shz::atan2fshz_atan2fComputes arctangent of y / x, using the signs of arguments to determine correct quadrant.
shz::asinfshz_asinfFast arcsine approximation; equivalent to C's asinf().
shz::acosfshz_acosfFast arccosine approximation; equivalent to C's acosf().
shz::asecfshz_asecfFast arcsecant/inverse secant approximation, taking units in radians.
shz::acscfshz_acscfFast arccosecant/inverse cosecant approximation; taking units in radians.
shz::acotfshz_acotfFast arccotangent/inverse cotangent approximation; taking units in radians.
shz::sinhfshz_sinhfFast hyperbolic sine function.
shz::coshfshz_coshfFast hyperbolic cosine function.
shz::tanhfshz_tanhfFast hyperbolic tangent function.
shz::cschfshz_cschfFast hyperbolic cosecant function.
shz::sechfshz_sechfFast hyperbolic secant function.
shz::cothfshz_cothfFast hyperbolic cotangent function.
shz::asinhfshz_asinhfFast hyperbolic arcsine function.
shz::acoshfshz_acoshfFast hyperbolic arccosine function.
shz::atanhfshz_atanhfFast hyperbolic arctangent function.
shz::acschfshz_acschfFast hyperbolic arccosecant function.
shz::asechfshz_asechfFast hyperbolic arcsecant function.
shz::acothfshz_acothfFast hyperbolic arccotangent function.
shz::lgammafshz_lgammafFast approximation for C's lgammaf().
shz::tgammafshz_tgammafFast approximation for C's tgammaf().
C++C functionDescription
shz::operator+shz_vec_addC type-generic vector addition.
shz::operator-shz_vec_subC type-generic vector subtraction.
shz::operator*shz_vec_mulC type-generic vector multiplication.
shz::operator/shz_vec_divC type-generic vector division.
shz::operator*shz_vec_scaleC type-generic vector scaling.
shz::operator*shz_vec_scaleC type-generic vector scaling.
shz::operator/shz_vec_divfC type-generic vector division by a scalar.
shz::operator/shz_vec_divC type-generic vector division.
C++C functionDescription
shz::operator+shz_caddfAdds two complex numbers together and returns the result.
shz::operator-shz_csubfSubtracts rhs from lhs and returns the complex result.
shz::operator*shz_cmulfMultiplies two complex numbers together, returning the complex result.
shz::operator*shz_cscalefScales both componets of the complex number, c, by the value, v, returning the result.
shz::operator/shz_cdivfDivides lhs by rhs, returning the complex result.
shz::operator/shz_cscalefScales both componets of the complex number, c, by the value, v, returning the result.
shz::operator==shz_cequalfChecks for equality between two complex numbers with either an absolute or relative tolerance.
shz::cinitfshz_cinitfReturns a complex number which has been initialized to contain the given component values.
shz::cpolarfshz_cpolarfReturns a complex number with a magnitude of r, and a phase angle of theta (in radians).
shz::cequalfshz_cequalfChecks for equality between two complex numbers with either an absolute or relative tolerance.
shz::crealfshz_crealfReturns the real component of a complex number.
shz::cimagfshz_cimagfReturns the imaginary component of a complex number.
shz::caddfshz_caddfAdds two complex numbers together and returns the result.
shz::csubfshz_csubfSubtracts rhs from lhs and returns the complex result.
shz::cmulfshz_cmulfMultiplies two complex numbers together, returning the complex result.
shz::cdivfshz_cdivfDivides lhs by rhs, returning the complex result.
shz::cscalefshz_cscalefScales both componets of the complex number, c, by the value, v, returning the result.
shz::crecipfshz_crecipfReturns the multiplicative inverse or reciprocal of the complex number, c.
shz::cabsfshz_cabsfReturns the absolute value (or magnitude) of the complex number, c.
shz::inv_cabsfshz_inv_cabsfReturns the inverse of the absolute value (or inverse of the magnitude) of the complex number, c.
shz::cnormfshz_cnormfReturns the squared magnitude of the complex number, c.
shz::cargfshz_cargfReturns the phase angle of the complex number, c.
shz::conjfshz_conjfReturns the complex conjugate of c.
shz::cprojfshz_cprojfCalculates the projection of the complex number, c, onto the Riemann sphere.
shz::csqrtfshz_csqrtfComputes and returns the complex square root of c.
shz::cpowfshz_cpowfRaises the complex base to the complex exp power, returning a complex result.
shz::cexpfshz_cexpfReturns the complex base e exponential of c.
shz::clogfshz_clogfComputes and returns the complex natural logarithm of c.
shz::clog10fshz_clog10fComputes and returns the complex base 10 logarithm of c.
shz::csinfshz_csinfCalculates and returns the complex sine of c.
shz::ccosfshz_ccosfCalculates and returns the complex cosine of c.
shz::ctanfshz_ctanfCalculates and returns the complex tangent of c.
shz::ccscfshz_ccscfCalculates and returns the complex cosecant of c.
shz::csecfshz_csecfCalculates and returns the complex secant of c.
shz::ccotfshz_ccotfCalculates and returns the complex cotangent of c.
shz::casinfshz_casinfCalculates and returns the complex arcsine of c.
shz::cacosfshz_cacosfCalculates and returns the complex arccosine of c.
shz::catanfshz_catanfCalculates and returns the complex arctangent of c.
shz::cacscfshz_cacscfCalculates and returns the complex arccosecant of c.
shz::casecfshz_casecfCalculates and returns the complex arcsecant of c.
shz::cacotfshz_cacotfCalculates and returns the complex arccotangent of c.
shz::csinhfshz_csinhfCalculates and returns the complex hyperbolic sine of c.
shz::ccoshfshz_ccoshfCalculates and returns the complex hyperbolic cosine of c.
shz::ctanhfshz_ctanhfCalculates and returns the complex hyperbolic tangent of c.
shz::ccschfshz_ccschfCalculates and returns the complex hyperbolic cosecant of c.
shz::csechfshz_csechfCalculates and returns the complex hyperbolic secant of c.
shz::ccothfshz_ccothfCalculates and returns the complex hyperbolic cotangent of c.
shz::casinhfshz_casinhfCalculates and returns the complex hyperbolic arcsine of c.
shz::cacoshfshz_cacoshfCalculates and returns the complex hyperbolic arccosine of c.
shz::catanhfshz_catanhfCalculates and returns the complex hyperbolic arctangent of c.
shz::cacschfshz_cacschfCalculates and returns the complex hyperbolic arccosecant of c.
shz::casechfshz_casechfCalculates and returns the complex hyperbolic arcsecant of c.
shz::cacothfshz_cacothfCalculates and returns the complex hyperbolic arccotangent of c.
shz::fftshz_fftFast Fourier Transform.
C++C functionDescription
shz::dcache_alloc_lineshz_dcache_alloc_line
shz::memcpy1shz_memcpy1
shz::memcpy2shz_memcpy2
shz::memcpy4shz_memcpy4
shz::memcpy8shz_memcpy8
shz::memset8shz_memset8
shz::memcpy32shz_memcpy32
shz::memcpy64shz_memcpy64
shz::memcpy128shz_memcpy128
shz::memcpy2_8shz_memcpy2_8
shz::memcpy2_16shz_memcpy2_16
shz::memset2_16shz_memset2_16
shz::memcpy4_16shz_memcpy4_16
shz::memswap32_1shz_memswap32_1
shz::memswap32_1_xmtrxshz_memswap32_1_xmtrx
shz::sq_memcpy32shz_sq_memcpy32
shz::sq_memcpy32_xmtrxshz_sq_memcpy32_xmtrx
shz::sq_memcpy32_1shz_sq_memcpy32_1
shz::sq_memcpy32_1_xmtrxshz_sq_memcpy32_1_xmtrx
C++C functionDescription
shz::backend_linkedshz_backend_linkedReturns the integer ID for which SHZ_BACKEND the linked-to library was built with.
C++DefinitionDescription
shz::is_radians_v`inline constexpr bool is_radians_v = (std::is_arithmetic_v && ...) && (std::is_floating_point_v
shz::fipr_max_errorconstexpr float fipr_max_error = 0.1f;
shz::pi_fconstexpr float pi_f = SHZ_F_PI;Floating-point constant approximation for Pi.
shz::tau_fconstexpr float tau_f = SHZ_F_TAU;Floating-point constant approximation for Pi*2.
shz::pi_f_2constexpr float pi_f_2 = SHZ_F_PI_2;Floating-point constant approximation for Pi/2.
shz::pi_f_4constexpr float pi_f_4 = SHZ_F_PI_4;Floating-point constant approximation for Pi/4.
shz::fsca_rad_factorconstexpr float fsca_rad_factor = SHZ_FSCA_RAD_FACTOR;Scaling factor used to scale the input to FSCA from radians.
shz::fsca_deg_factorconstexpr float fsca_deg_factor = SHZ_FSCA_DEG_FACTOR;Scaling factor used to scale the input to FSCA from degrees.