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::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 += 1.0f.
shz::normalizef_fsrrashz_normalizef_fsrraMaps a value within the given range from to to, to be within the range of 0.0f + 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 the outputEnd - outputStart 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::fdimfshz_fdimfReplacement for the <math.h> routine, fdimf(),.
shz::hypotfshz_hypotfReplacement for the <math.h> routine, hypotf().
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::cbrtfshz_cbrtfReplacement for the <math.h> routine, cbrtf().
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::sqrtfshz_sqrtfReturns the fast approximate square root of the given value, x, safely returning 0.0f is x == 0.0f.
shz::invf_fsrrashz_invf_fsrraTakes the inverse of x using a very fast approximation, returning a positive result.
shz::invfshz_invfTakes the inverse of x using a slighty faster approximation than doing a full division, safely handling negative values.
shz::divf_fsrrashz_divf_fsrraDivides num by denom using a very fast approximation, which requires denom be a positive value.
shz::divfshz_divfDivides num by denom using a slightly faster approximation, allowing denom to be negative.
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::pow2fshz_pow2fFast approximation for raising 2 to a floating-point power.
shz::powfshz_powfFast approximation for C's powf().
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::operator/shz_invfTakes the inverse of x using a slighty faster approximation than doing a full division, safely handling negative values.
shz::operator/shz_invfTakes the inverse of x using a slighty faster approximation than doing a full division, safely handling negative values.
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 quadtrant. Equivalent to C's atan2f().
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.
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_scaleC type-generic vector scaling.
shz::operator/shz_vec_divC type-generic vector division.
C++C functionDescription
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::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::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_lineIntrinsic around the SH4 MOVCA.L instruction.
shz::memcpyshz_memcpyGeneric drop-in fast memcpy() replacement.
shz::memcpy1shz_memcpy1Copies an unaligned buffer to another one byte at a time.
shz::memcpy2shz_memcpy2Copies from one 2-byte aligned buffer to another two bytes at a time.
shz::memcpy4shz_memcpy4Copies a from one 4-byte aligned buffer to another 4 bytes at a time.
shz::memcpy8shz_memcpy8Copies a from one 8-byte aligned buffer to another 8 bytes at a time.
shz::memset8shz_memset8Assigns the given 8-byte value to the bytes in dst.
shz::memcpy32shz_memcpy32Copies bytes from the src to the dst buffer in 32-byte chunks.
shz::memcpy64shz_memcpy64Specialized memcpy() variant for copying multiples of 64-bytes.
shz::memcpy2_8shz_memcpy2_8Copies 8 shorts from src to dst.
shz::memcpy2_16shz_memcpy2_16Copies 16 shorts from src to dst.
shz::memset2_16shz_memset2_16Sets the values of the 16 shorts pointed to by dst to the given value.
shz::memcpy4_16shz_memcpy4_16Copies 16 4-byte, long values from src to dst.
shz::memswap32_1shz_memswap32_1Swaps the values within the given 32-byte buffers.
shz::memswap32_1_xmtrxshz_memswap32_1_xmtrxSwaps the values within the given 32-byte buffers, using XMTRX.
shz::sq_memcpy32shz_sq_memcpy32Copies bytes from src to dst in 32-byte chunks, using the Store Queues.
shz::sq_memcpy32_xmtrxshz_sq_memcpy32_xmtrxCopies bytes from src to dst in 32-byte chunks, using the Store Queues and XMTRX.
shz::sq_memcpy32_1shz_sq_memcpy32_1Copies src to dst in a single 32-byte transaction using the Store Queues.
shz::sq_memcpy32_1_xmtrxshz_sq_memcpy32_1_xmtrxCopies src to dst in a single 32-byte transaction using the Store Queues and XMTRX.
shz::memmoveshz_memmoveGeneric drop-in fast memmove() replacement.
shz::memcpy128shz_memcpy128Specialized memcpy() variant for copying multiples of 128 bytes.
C++DefinitionDescription
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.