Raven Engine v0.1
Loading...
Searching...
No Matches
Crux::Detail Namespace Reference

Classes

struct  CosCoeffs
 Polynomial coefficient table for cosine approximations on [-pi/4, pi/4]. More...
struct  CosCoeffs< 5 >
 Degree-5 cosine: cos(x) ~= c0 + c2*x^2 + c4*x^4. More...
struct  CosCoeffs< 7 >
 Degree-7 cosine: cos(x) ~= c0 + c2*x^2 + c4*x^4 + c6*x^6. More...
struct  CosCoeffs< 9 >
 Degree-9 cosine: cos(x) ~= c0 + c2*x^2 + c4*x^4 + c6*x^6 + c8*x^8. More...
struct  SinCoeffs
 Polynomial coefficient table for sine approximations on [-pi/4, pi/4]. More...
struct  SinCoeffs< 5 >
 Degree-5 sine: sin(x) ~= c1*x + c3*x^3 + c5*x^5. More...
struct  SinCoeffs< 7 >
 Degree-7 sine: sin(x) ~= c1*x + c3*x^3 + c5*x^5 + c7*x^7. More...
struct  SinCoeffs< 9 >
 Degree-9 sine: sin(x) ~= c1*x + c3*x^3 + c5*x^5 + c7*x^7 + c9*x^9. More...

Enumerations

enum class  PrecisionMode { Fast , Standard , High }
 Precision modes for selecting polynomial degree. More...

Functions

template<PrecisionMode Mode>
constexpr float PolySin (float x)
 Dispatch to the appropriate degree-xx sine polynomial.
template<PrecisionMode Mode>
constexpr float PolyCos (float x)
 Dispatch to the appropriate degree-xx cosine polynomial.
template<int Degree>
constexpr float PolySinImpl (float x)
 Generic Estrin-based sine polynomial of degree D on x in [-pi/4,pi/4].
template<>
float PolySinImpl< 5 > (float x)
template<>
float PolySinImpl< 7 > (float x)
template<>
float PolySinImpl< 9 > (float x)
template<int Degree>
constexpr float PolyCosImpl (float x)
 Generic Estrin-based cosine polynomial of degree D on x in [-pi/4,pi/4].
template<>
float PolyCosImpl< 5 > (float x)
template<>
float PolyCosImpl< 7 > (float x)
template<>
float PolyCosImpl< 9 > (float x)

Local constants for range reduction (float)

void ReduceAngle (float x, float &outXr, unsigned int &outQuad) noexcept
 Reduce angle into [-pi/4, pi/4] and extract quadrant.

Enumeration Type Documentation

◆ PrecisionMode

enum class Crux::Detail::PrecisionMode
strong

Precision modes for selecting polynomial degree.

Enumerator
Fast 

degree 5 approximation (lowest accuracy, highest speed)

Standard 

degree 7 approximation (default tradeoff)

High 

degree 9 approximation (highest accuracy)

Function Documentation

◆ PolyCos()

template<PrecisionMode Mode>
float Crux::Detail::PolyCos ( float x)
inlineconstexpr

Dispatch to the appropriate degree-xx cosine polynomial.

Template Parameters
ModeDesired precision mode.
Parameters
xInput in [-pi/4, pi/4].
Returns
Approximated cos(x).

◆ PolyCosImpl()

template<int Degree>
float Crux::Detail::PolyCosImpl ( float x)
inlineconstexpr

Generic Estrin-based cosine polynomial of degree D on x in [-pi/4,pi/4].

Template Parameters
DegreePolynomial degree (must be even: 5,7,9).
Parameters
xReduced input in [-pi/4,pi/4].
Returns
Approximation of cos(x).

◆ PolyCosImpl< 5 >()

template<>
float Crux::Detail::PolyCosImpl< 5 > ( float x)
inline

◆ PolyCosImpl< 7 >()

template<>
float Crux::Detail::PolyCosImpl< 7 > ( float x)
inline

◆ PolyCosImpl< 9 >()

template<>
float Crux::Detail::PolyCosImpl< 9 > ( float x)
inline

◆ PolySin()

template<PrecisionMode Mode>
float Crux::Detail::PolySin ( float x)
inlineconstexpr

Dispatch to the appropriate degree-xx sine polynomial.

Template Parameters
ModeDesired precision mode.
Parameters
xInput in [-pi/4, pi/4].
Returns
Approximated sin(x).

◆ PolySinImpl()

template<int Degree>
float Crux::Detail::PolySinImpl ( float x)
inlineconstexpr

Generic Estrin-based sine polynomial of degree D on x in [-pi/4,pi/4].

Template Parameters
DegreePolynomial degree (must be odd: 5,7,9).
Parameters
xReduced input in [-pi/4,pi/4].
Returns
Approximation of sin(x).

◆ PolySinImpl< 5 >()

template<>
float Crux::Detail::PolySinImpl< 5 > ( float x)
inline

◆ PolySinImpl< 7 >()

template<>
float Crux::Detail::PolySinImpl< 7 > ( float x)
inline

◆ PolySinImpl< 9 >()

template<>
float Crux::Detail::PolySinImpl< 9 > ( float x)
inline

◆ ReduceAngle()

void Crux::Detail::ReduceAngle ( float x,
float & outXr,
unsigned int & outQuad )
inlinenoexcept

Reduce angle into [-pi/4, pi/4] and extract quadrant.

1) Scale x by 2/pi to get k. 2) Round k to nearest int without branches. 3) Subtract k*(pi/2) using two-step FMA (hi then lo). 4) Compute quadrant = k mod 4.

Parameters
xInput angle in radians.
outXr[out] Reduced angle in [-pi/4, pi/4].
outQuad[out] Quadrant index in {0,1,2,3}.

The caller uses outQuad to decide sine vs cosine and sign.