Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt

Use this file to discover all available pages before exploring further.

Maths is a static, partial class in the Prowl.Vector namespace that centralizes all mathematical constants and scalar/vector utility functions. Every method has overloads for float, double, and the vector types Float2/3/4 and Double2/3/4 (and integer vectors where applicable). All methods are marked [MethodImpl(AggressiveInlining)].

Declaration

public static partial class Maths

Constants

Basic Constants

ConstantValueDescription
PI3.14159265fMathematical constant π.
E2.71828182fEuler’s number.
TwoPI / Tau6.28318530f2π — full circle in radians.
PI_21.57079632fπ / 2.
PI_31.04719755fπ / 3.
PI_40.78539816fπ / 4.
PI_60.52359877fπ / 6.
PI_80.39269908fπ / 8.
Three_PI_24.71238898f3π / 2.
One_PI0.31830988f1 / π.
Two_PI0.63661977f2 / π.
Four_PI1.27323954f4 / π.

Square Roots

ConstantValueDescription
Sqrt21.41421356f√2.
Sqrt31.73205080f√3.
Sqrt52.23606797f√5.
Sqrt_PI1.77245385f√π.
Sqrt_E1.64872127f√e.
One_Sqrt20.70710678f1 / √2.
One_Sqrt_PI0.56418949f1 / √π.
Sqrt_TwoPI2.50662827f√(2π).
One_Sqrt_TwoPI0.39894228f1 / √(2π) — Gaussian normalization factor.
Sqrt_Two_PI0.79788456f√(2/π).

Logarithms

ConstantValueDescription
Ln20.69314718fln(2).
Ln31.09861228fln(3).
Ln102.30258509fln(10).
Log2_E1.44269504flog₂(e).
Log10_E0.43429448flog₁₀(e).
Log10_20.30102999flog₁₀(2).

Degree / Radian Conversion

ConstantValueDescription
Deg2Rad0.01745329fMultiply by this to convert degrees → radians.
Rad2Deg57.2957795fMultiply by this to convert radians → degrees.

Trigonometric Values

ConstantValueDescription
Sin_PI_40.70710678fsin(π/4) = cos(π/4) = 1/√2.
Sin_PI_30.86602540fsin(π/3) = √3/2.
Sin_PI_60.5fsin(π/6).
Tan_PI_41.0ftan(π/4).
Tan_PI_31.73205080ftan(π/3) = √3.
Tan_PI_60.57735026ftan(π/6) = 1/√3.

Special / Physics Constants

ConstantValueDescription
GoldenRatio1.61803398fGolden ratio φ.
SilverRatio2.41421356fSilver ratio 1 + √2.
EulerGamma0.57721566fEuler–Mascheroni constant γ.
Catalan0.91596559fCatalan’s constant.
E_Neg_Half0.60653065fe^(−0.5).
SpeedOfLight299792458fSpeed of light in vacuum (m/s).
StandardGravity9.80665fStandard gravitational acceleration (m/s²).
StandardTemperature273.15fStandard temperature in Kelvin (0 °C).
AbsoluteZero-273.15fAbsolute zero in °C.

Common Fractions

ConstantValue
Half0.5
Third1/3
TwoThirds2/3
Quarter0.25
ThreeQuarters0.75
Sixth1/6
FiveSixths5/6

Precision

ConstantDescription
Epsilonfloat.Epsilon — smallest positive float.
MinValuefloat.MinValue.
MaxValuefloat.MaxValue.
PositiveInfinityfloat.PositiveInfinity.
NegativeInfinityfloat.NegativeInfinity.
NaNfloat.NaN.

Methods

All functions are overloaded for scalar types (float, double, int) and vector types (Float2, Float3, Float4, Double2, Double3, Double4, Int2, Int3, Int4) unless noted otherwise. Vector overloads operate component-wise.

Basic Math

SignatureDescription
Abs(float x) : floatAbsolute value.
Acos(float x) : floatArc cosine in radians, domain [−1, 1].
Asin(float x) : floatArc sine in radians, domain [−1, 1].
Atan(float x) : floatArc tangent in radians.
Atan2(float x, float y) : floatFour-quadrant arc tangent of x/y.
Cos(float x) : floatCosine in radians.
Sin(float x) : floatSine in radians.
Tan(float x) : floatTangent in radians.
Exp(float x) : floate^x.
Exp2(float x) : float2^x.
Log(float x) : floatNatural logarithm.
Pow(float x, float y) : floatx raised to the power y.
Sqrt(float x) : floatSquare root.
Rsqrt(float x) : floatReciprocal square root (1/√x).
Sign(float x) : floatReturns −1, 0, or 1.
FMod(float x, float y) : floatFloating-point remainder (x % y).
Frac(float x) : floatFractional part: x − floor(x).
ModF(float x, out float integerPart) : floatSplits x into integer and fractional parts.
Step(float edge, float x) : floatReturns 0 if x < edge, else 1.
Smoothstep(float e0, float e1, float x) : floatSmooth Hermite interpolation between 0 and 1.

Clamping & Rounding

SignatureDescription
Clamp(float x, float min, float max) : floatClamps x to [min, max]. Overloaded for all numeric and vector types.
Saturate(float x) : floatClamps to [0, 1].
Min(float x, float y) : floatMinimum of two values.
Max(float x, float y) : floatMaximum of two values.
Floor(float x) : floatLargest integer ≤ x.
Ceiling(float x) : floatSmallest integer ≥ x.
Round(float x) : floatNearest integer (banker’s rounding).
FloorToInt(float x) : intFloor and cast to int.
CeilToInt(float x) : intCeiling and cast to int.
RoundToInt(float x) : intRound and cast to int.
Repeat(float t, float length) : floatWraps t to [0, length].
PingPong(float t, float length) : floatBounces t back and forth in [0, length].

Interpolation

SignatureDescription
Lerp(float a, float b, float t) : floatLinearly interpolates, t clamped to [0, 1].
LerpUnclamped(float a, float b, float t) : floatLerp without clamping t.
LerpAngle(float a, float b, float t) : floatLerp taking the shortest arc (in radians).
InverseLerp(float a, float b, float value) : floatReturns the t such that Lerp(a, b, t) = value. Returns 0 when a == b.
SmoothLerp(float a, float b, float t) : floatLerp with a cubic Hermite ease-in/ease-out.
Smoothstep(float e0, float e1, float x) : floatClassic GLSL-style smoothstep.

Remapping & Angle Utilities

SignatureDescription
Remap(float v, float iMin, float iMax, float oMin, float oMax) : floatMaps v from [iMin, iMax] to [oMin, oMax].
DeltaAngle(float current, float target) : floatShortest signed angle difference in radians.
ToDegrees(float radians) : floatConverts radians to degrees.
ToRadians(float degrees) : floatConverts degrees to radians.

Code Example

using Prowl.Vector;

// --- Constants ---
float circumference = 2f * Maths.PI * radius;
float halfDiag = Maths.Sqrt2 * sideLength / 2f;

// --- Clamping / Saturate ---
float health = Maths.Clamp(rawValue, 0f, 100f);
float normalized = Maths.Saturate(health / 100f);

// --- Lerp & Smoothstep ---
float t = (float)frame / totalFrames;
float smoothT = Maths.Smoothstep(0f, 1f, t);
Float3 position = Maths.Lerp(start, end, smoothT);

// --- Remap ---
// Convert a noise value from [-1, 1] to [0, 1]
float remapped = Maths.Remap(noiseValue, -1f, 1f, 0f, 1f);

// --- Angle utilities ---
float delta = Maths.DeltaAngle(currentAngle, targetAngle); // in radians
float deg = Maths.ToDegrees(Maths.PI / 6f); // 30

// --- Vector component-wise ---
Float3 clamped = Maths.Clamp(velocity, -maxSpeed, maxSpeed);
Float3 floored = Maths.Floor(worldPos); // snap to grid
Float3 frac    = Maths.Frac(worldPos);  // fractional cell offset

// --- Repeat / PingPong ---
float wrapped = Maths.Repeat(time, 10f);        // loops in [0, 10]
float bounced = Maths.PingPong(time, 5f);       // bounces in [0, 5]

Notes

  • All scalar overloads delegate to MathF (single-precision) or Math (double-precision) from the BCL, so performance matches the platform’s native math library.
  • Vector overloads expand to per-component scalar calls — there is no SIMD acceleration at this level.
  • Lerp clamps t to [0, 1] via Saturate. Use LerpUnclamped for extrapolation outside the range.
  • Remap does not clamp the input; wrap with Clamp first if you need bounded output.
  • DeltaAngle works in radians. Multiply inputs/outputs by Deg2Rad/Rad2Deg if working in degrees.

Build docs developers (and LLMs) love