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 (in Prowl.Vector) is a static class providing constants and scalar math functions that complement the vector and matrix types. Every method is decorated with [MethodImpl(MethodImplOptions.AggressiveInlining)] for zero-overhead usage in hot code paths, and most methods support all scalar types (float, double, int) as well as componentwise overloads for Float2/Float3/Float4, Double2/Double3/Double4, Int2/Int3/Int4.

Constants

Basic

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

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.56418958f1 / √π
Sqrt_TwoPI2.50662827f√(2π) — appears in the normal distribution
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)

Degrees / Radians

ConstantValueDescription
Deg2Rad0.01745329fMultiply a degree value by this to get radians (π / 180)
Rad2Deg57.2957795fMultiply a radian value by this to get degrees (180 / π)

Trigonometric Values

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

Common Fractions

ConstantValueDescription
Half0.5f1/2
Third0.33333333f1/3
TwoThirds0.66666666f2/3
Quarter0.25f1/4
ThreeQuarters0.75f3/4
Sixth0.16666666f1/6
FiveSixths0.83333333f5/6

Special Constants

ConstantValueDescription
GoldenRatio1.61803398fφ — the golden ratio
SilverRatio2.41421356f1 + √2
EulerGamma0.57721566fEuler–Mascheroni constant (γ)
Catalan0.91596559fCatalan’s constant
E_Neg_Half0.60653065fe^(−0.5)

Physics

ConstantValueDescription
SpeedOfLight299792458.0fSpeed of light in vacuum (m/s)
StandardGravity9.80665fStandard gravitational acceleration (m/s²)
StandardTemperature273.15fStandard temperature in Kelvin (0 °C)
AbsoluteZero−273.15fAbsolute zero in Celsius

Precision

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

Scalar Functions

All methods below support float and double scalar overloads. Most also have componentwise vector overloads for Float2/Float3/Float4 and Double2/Double3/Double4. Integer overloads are noted where available.

Interpolation

SignatureDescription
Lerp(float a, float b, float t)Linearly interpolates from a to b. t is clamped to [0, 1]. Formula: a + (b - a) * saturate(t).
LerpUnclamped(float a, float b, float t)Same as Lerp but t is not clamped — allows extrapolation.
LerpAngle(float a, float b, float t)Lerp between two angles (in radians), always taking the shortest arc around the circle.
SmoothLerp(float a, float b, float t)Lerp with a cubic Hermite ease-in/ease-out applied to t. Equivalent to Lerp(a, b, Smoothstep(0, 1, t)).
InverseLerp(float a, float b, float value)Returns the t that produces value in a Lerp(a, b, t) call. Returns 0 if a == b.
Remap(float value, float inputMin, float inputMax, float outputMin, float outputMax)Maps value from the input range [inputMin, inputMax] to the output range [outputMin, outputMax].
Smoothstep(float edge0, float edge1, float x)Smooth Hermite interpolation: returns 0 when x ≤ edge0, 1 when x ≥ edge1, and a smooth curve in-between. Uses t*t*(3 - 2*t).
PingPong(float t, float length)Bounces t back and forth between 0 and length, never exceeding either bound.
Repeat(float t, float length)Wraps t within [0, length) — similar to t % length but always positive.

Clamping and Rounding

SignatureDescription
Clamp(float x, float min, float max)Clamps x to [min, max]. Also supports int, uint, ulong, byte, ushort.
Saturate(float x)Shorthand for Clamp(x, 0, 1).
Floor(float x)Largest integer less than or equal to x. Returns float/double.
FloorToInt(float x)Floor cast directly to int.
Ceiling(float x)Smallest integer greater than or equal to x. Returns float/double.
CeilToInt(float x)Ceiling cast directly to int.
Round(float x)Rounds to the nearest integer (midpoint rounds to even). Returns float/double.
RoundToInt(float x)Round cast directly to int.
Abs(float x)Absolute value. Also supports int.
Sign(float x)Returns −1, 0, or 1 based on the sign of x. Also supports int.
Min(float x, float y)Returns the smaller of two values. Also supports int, uint, ulong, byte, ushort.
Max(float x, float y)Returns the larger of two values. Also supports int, uint, ulong, byte, ushort.
Step(float edge, float x)Returns 0 if x < edge, otherwise 1.
Frac(float x)Fractional part of x: x - Floor(x). Always in [0, 1).
FMod(float x, float y)Floating-point remainder: x % y.
ModF(float x, out float integerPart)Splits x into its integer and fractional parts simultaneously.

Trigonometric

All trig functions accept float/double scalars and float/double vector types.
SignatureDescription
Sin(float x)Sine of x (radians).
Cos(float x)Cosine of x (radians).
Tan(float x)Tangent of x (radians).
Asin(float x)Arc sine — returns value in [−π/2, π/2].
Acos(float x)Arc cosine — returns value in [0, π].
Atan(float x)Arc tangent — returns value in [−π/2, π/2].
Atan2(float x, float y)Two-argument arc tangent. Returns the angle of vector (x, y) in [−π, π].
DeltaAngle(float current, float target)Shortest signed angle (in radians) from current to target, wrapping at ±π.

Power and Exponential

SignatureDescription
Pow(float x, float y)x raised to the power of y.
Sqrt(float x)Square root of x.
Rsqrt(float x)Reciprocal square root: 1 / sqrt(x).
Exp(float x)e raised to the power of x.
Exp2(float x)2 raised to the power of x.
Log(float x)Natural logarithm of x.

Angle Conversion

SignatureDescription
ToDegrees(float radians)Converts radians to degrees.
ToRadians(float degrees)Converts degrees to radians.
Both methods have componentwise overloads for all vector types (Float2/Float3/Float4, Double2/Double3/Double4).

Code Example

using Prowl.Vector;

// --- Lerp, Clamp, and Remap together ---

// Suppose a game object has health in [0, 100].
// We want to map health to a colour blend factor in [0, 1]
// and then smoothly interpolate a UI bar width.

float health       = 73.5f;
float healthNorm   = Maths.InverseLerp(0f, 100f, health);   // ≈ 0.735
float barWidth     = Maths.Lerp(0f, 400f, healthNorm);      // ≈ 294 px
float smoothWidth  = Maths.SmoothLerp(0f, 400f, healthNorm);// eased version

// Clamp an input delta so the bar never snaps too fast
float deltaTime = 0.016f;
float maxDelta  = 50f;
float safeDelta = Maths.Clamp(deltaTime * 1000f, 0f, maxDelta); // ≤ 50

// Remap noise output [-1, 1] → [0, 1] for use as a height value
float rawNoise  = Noise.SNoise(new Float2(3.7f, 1.2f)); // ≈ −0.42
float height    = Maths.Remap(rawNoise, -1f, 1f, 0f, 1f);  // ≈ 0.29

// Angle interpolation — smoothly rotate from 350° to 10° (crosses 0)
float fromAngle = Maths.ToRadians(350f);
float toAngle   = Maths.ToRadians(10f);
float t         = 0.5f;
float midAngle  = Maths.LerpAngle(fromAngle, toAngle, t);   // ≈ 0° (correctly wraps)

Build docs developers (and LLMs) love