Raven Engine v0.1
Loading...
Searching...
No Matches
Math

Mathematical operations and algorithms. More...

Files

file  TrigPolyImpl.inl
 Estrin-based polynomial evaluation for sine and cosine.

Functions

template<typename T>
constexpr T Crux::Lerp (T a, T b, float t)
 Linear interpolation between a and b by factor t.
template<typename T>
constexpr T Crux::Min (T a, T b)
 Return the minimum of two values.
template<typename T>
constexpr T Crux::Max (T a, T b)
 Return the maximum of two values.
template<typename T>
constexpr T Crux::Clamp (T value, T min, T max)
 Clamp a value between a minimum and maximum.
template<typename T>
constexpr T Crux::Saturate (T value)
 Clamp a value to the [0,1] range.
template<typename T>
constexpr T Crux::Sign (T value)
 Signum function: returns -1, 0, or +1.
template<typename T>
constexpr T Crux::Abs (T value)
 Absolute value.
template<typename T>
constexpr T Crux::Floor (T value)
 Floor function for floating-point values.
template<typename T>
constexpr T Crux::Ceil (T value)
 Ceiling function for floating-point values.
template<typename T>
constexpr T Crux::Fract (T value)
 Fractional part of a value.
template<typename T>
constexpr T Crux::Square (T value)
 Square of a value.
template<typename T>
constexpr T Crux::Cube (T value)
 Cube of a value.
constexpr float Crux::Smoothstep (float edge0, float edge1, float x)
 Smoothstep interpolation between edge0 and edge1.
constexpr float Crux::CTInverseSqrt (float x)
 Fast compile-time inverse square root (single Newton step).
constexpr float Crux::CTSqrt (const float x)
 Fast compile-time square root using bit manipulation.
float Crux::InverseSqrt (const float x)
 Inverse square root using hardware rsqrt.
float Crux::Sqrt (const float x)
 Standard square root using hardware sqrt.
constexpr float Crux::Radians (float degrees)
 Convert degrees to radians.
constexpr Vector< float, 3 > Crux::Radians (Vector< float, 3 > vector)
 Convert a Vector3s components from degrees to radians.
constexpr float Crux::Degrees (float radians)
 Convert radians to degrees.
constexpr Vector< float, 3 > Crux::Degrees (Vector< float, 3 > vector)
 Convert a Vector3s components from radians to degrees.
template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
float Crux::Sin (float radians)
 Computes the sine of an angle in radians using a fast polynomial approximation.
template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
float Crux::Cos (float radians)
 Computes the cosine of an angle in radians using a fast polynomial approximation.

Detailed Description

Mathematical operations and algorithms.

Houses core arithmetic and math utilities.

Function Documentation

◆ Abs()

template<typename T>
T Crux::Abs ( T value)
inlineconstexpr

Absolute value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
Non-negative absolute of value.

◆ Ceil()

template<typename T>
T Crux::Ceil ( T value)
inlineconstexpr

Ceiling function for floating-point values.

Template Parameters
TFloating-point type.
Parameters
valueInput value.
Returns
Smallest integer >= value as T.

◆ Clamp()

template<typename T>
T Crux::Clamp ( T value,
T min,
T max )
inlineconstexpr

Clamp a value between a minimum and maximum.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
minMinimum allowed.
maxMaximum allowed.
Returns
Clamped value in [min, max].

◆ Cos()

template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
float Crux::Cos ( float radians)
inline

Computes the cosine of an angle in radians using a fast polynomial approximation.

Performs a branchless range-reduction into [-pi/4, pi/4], shifts the quadrant index for the pi/2 phase offset (cos(x)=sin(x+pi/2)), evaluates a minimax polynomial of degree determined by the PrecisionMode template (Standard=7), and applies the correct sign.

Template Parameters
PrecisionModeSelects the polynomial degree:
  • UltraFast (degree 5)
  • Standard (degree 7, default)
  • High (degree 9) It is recommended to use Standard for most applications.
Parameters
radiansAngle in radians.
Returns
Approximation of cos(radians).
Note
This uses the internal Detail::ReduceAngle and Detail::PolyCos<PrecisionMode> routines.
See also
Detail::ReduceAngle, Detail::PolyCos

◆ CTInverseSqrt()

float Crux::CTInverseSqrt ( float x)
inlineconstexpr

Fast compile-time inverse square root (single Newton step).

Note
This is an approximation and may not be accurate for all values. Prefer using the provided Hardware InverseSqrt function. Only use if you need the value at Compile-Time
Warning
Entering 0.0f will result in a really large number.
Parameters
xInput value.
Returns
Approximate 1/sqrt(x).

◆ CTSqrt()

float Crux::CTSqrt ( const float x)
inlineconstexpr

Fast compile-time square root using bit manipulation.

Note
This is an approximation and may not be accurate for all values. Prefer using the provided Hardware Sqrt function. Only use if you need the value at Compile-Time
Warning
Entering a negative value will result in inf.
Parameters
xInput value.
Returns
Approximate sqrt(x).

◆ Cube()

template<typename T>
T Crux::Cube ( T value)
inlineconstexpr

Cube of a value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
value * value * value.

◆ Degrees() [1/2]

float Crux::Degrees ( float radians)
inlineconstexpr

Convert radians to degrees.

Parameters
radiansAngle in radians.
Returns
Angle in degrees.

◆ Degrees() [2/2]

Vector< float, 3 > Crux::Degrees ( Vector< float, 3 > vector)
inlineconstexpr

Convert a Vector3s components from radians to degrees.

Parameters
vectorThe Vector to convert
Returns
A vector with all its components turned from radians to degrees

◆ Floor()

template<typename T>
T Crux::Floor ( T value)
inlineconstexpr

Floor function for floating-point values.

Template Parameters
TFloating-point type.
Parameters
valueInput value.
Returns
Largest integer <= value as T.

◆ Fract()

template<typename T>
T Crux::Fract ( T value)
inlineconstexpr

Fractional part of a value.

Template Parameters
TFloating-point type.
Parameters
valueInput value.
Returns
value - floor(value).

◆ InverseSqrt()

float Crux::InverseSqrt ( const float x)
inline

Inverse square root using hardware rsqrt.

Warning
Entering 0.0f will result in infinity.
Parameters
xInput value.
Returns
1.0f / sqrt(x).

◆ Lerp()

template<typename T>
T Crux::Lerp ( T a,
T b,
float t )
inlineconstexpr

Linear interpolation between a and b by factor t.

Template Parameters
TArithmetic type of endpoints.
Parameters
aStart value.
bEnd value.
tInterpolation factor in [0,1].
Returns
Interpolated value.

◆ Max()

template<typename T>
T Crux::Max ( T a,
T b )
inlineconstexpr

Return the maximum of two values.

Template Parameters
TArithmetic type.
Parameters
aFirst value.
bSecond value.
Returns
Larger of a and b.

◆ Min()

template<typename T>
T Crux::Min ( T a,
T b )
inlineconstexpr

Return the minimum of two values.

Template Parameters
TArithmetic type.
Parameters
aFirst value.
bSecond value.
Returns
Smaller of a and b.

◆ Radians() [1/2]

float Crux::Radians ( float degrees)
inlineconstexpr

Convert degrees to radians.

Parameters
degreesAngle in degrees.
Returns
Angle in radians.

◆ Radians() [2/2]

Vector< float, 3 > Crux::Radians ( Vector< float, 3 > vector)
inlineconstexpr

Convert a Vector3s components from degrees to radians.

Parameters
vectorThe Vector to convert
Returns
A vector with all its components turned from degress to radians

◆ Saturate()

template<typename T>
T Crux::Saturate ( T value)
inlineconstexpr

Clamp a value to the [0,1] range.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
Saturated value in [0,1].

◆ Sign()

template<typename T>
T Crux::Sign ( T value)
inlineconstexpr

Signum function: returns -1, 0, or +1.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
+1 if value > 0, -1 if value < 0, 0 if value == 0.

◆ Sin()

template<Detail::PrecisionMode Mode = Detail::PrecisionMode::Standard>
float Crux::Sin ( float radians)
inline

Computes the sine of an angle in radians using a fast polynomial approximation.

Performs a branchless range-reduction into [-pi/4, pi/4], evaluates a minimax polynomial of degree determined by the PrecisionMode template (Standard=7), and applies the correct sign based on the original quadrant.

Template Parameters
PrecisionModeSelects the polynomial degree:
  • UltraFast (degree 5)
  • Standard (degree 7, default)
  • High (degree 9)

It is recommended to use Standard for most applications.

Parameters
radiansAngle in radians.
Returns
Approximation of sin(radians).
Note
This uses the internal Detail::ReduceAngle and Detail::PolySin<PrecisionMode> routines.
See also
Detail::ReduceAngle, Detail::PolySin

◆ Smoothstep()

float Crux::Smoothstep ( float edge0,
float edge1,
float x )
inlineconstexpr

Smoothstep interpolation between edge0 and edge1.

Parameters
edge0Lower edge of interpolation.
edge1Upper edge of interpolation.
xValue to interpolate.
Returns
Interpolated result in [0,1].

◆ Sqrt()

float Crux::Sqrt ( const float x)
inline

Standard square root using hardware sqrt.

Warning
Entering a negative value will result in -nan.
Parameters
xInput value.
Returns
sqrt(x).

◆ Square()

template<typename T>
T Crux::Square ( T value)
inlineconstexpr

Square of a value.

Template Parameters
TArithmetic type.
Parameters
valueInput value.
Returns
value * value.