A few scalar helpers added to the global Math. No import, call them like Math.sin.
Overview
Interpolation
clamp, lerp, inverseLerp, smoothStep, remap.
Angle units
toRadians, toDegrees.
Arguments must be numbers. Anything else throws TypeError, there’s no coercion.
Interpolation
clamp
Keeps value between min and max. Swapped bounds work too.
lerp
a at t = 0, b at t = 1. t isn’t clamped, so values outside 0–1 overshoot.
inverseLerp
Where value sits between a and b, as 0–1. Not clamped. Returns 0 when a === b.
smoothStep
Like lerp, but eased in and out. t is clamped to 0–1.
remap
Maps value from one range to another. Not clamped, and inMin === inMax gives outMin.
Health → color
Distance → alpha
Out-of-range input goes out of range: HP 120 mapped 0..100 → 0..255 gives 306.
Wrap it in clamp when the input can overshoot.
Angle units
Game angles (QAngle) are in degrees. Math.sin and friends want radians.
Example
A name tag that fades out with distance.