@maruaudio/dsp/math/range is the package's f64 range policy, compatible with the Audio SDK. clamp(value, minimum, maximum) is exactly Math.min(maximum, Math.max(minimum, value)), so signed zero, reversed bounds and non-finite values follow ECMAScript Math.min/Math.max. clampFinite first replaces a non-finite input with a fallback, then clamps.
Functions
| Name | Inputs | Output | Domain as coded |
|---|---|---|---|
clamp | value, minimum, maximum | inclusive bound | NaN value or bound → NaN; ±Infinity lands on the nearest bound; reversed bounds return maximum |
clampUnit | value | clamp(value, 0, 1) | NaN stays NaN; −0 → 0 |
isFiniteNumber | value | boolean | false for NaN and ±Infinity, without Number.isFinite |
clampFinite | value, minimum, maximum, fallback = minimum | clamp of value, or of fallback when value is not finite | The fallback is clamped too |
clampFiniteWithFallback | same, fallback required | same | Explicit form for restricted realtime callers |
Lifecycle
None. Stateless functions with no preparation or instance state.
When to use it
Bound a parameter, a control value or a computed coefficient wherever the package's shared clamp semantics are wanted. Use clampFinite at an input boundary that must never pass NaN or infinity downstream.
Limits
clamppropagates NaN. OnlyclampFiniteandclampFiniteWithFallbacksubstitute; a NaN bound still yields NaN from them.- Signed zero follows the min/max order:
clamp(-0, 0, 1)is +0 andclamp(0, -1, -0)is −0. clampFinite's default argument is not in the realtime call graph; restricted callers useclampFiniteWithFallback.- Some leaves use their own conditional clamp instead, which passes NaN through unchanged, and
@maru/math-float-clampignores NaN like Cfmin/fmax.