@maruaudio/dsp/math/float-clamp reproduces DaisySP's fclamp, the fmin(fmax(value, minimum), maximum) clamp the CHOMPI firmware uses. Operands are rounded to f32 first. Unlike Math.min/Math.max, C's fmax and fmin ignore a NaN operand, so a NaN value clamps to minimum and a NaN bound is skipped. Ties follow newlib's fmaxf/fminf (x > y ? x : y): the second operand wins, which decides signed zero.
Functions
| Name | Inputs | Output | Domain as coded |
|---|---|---|---|
floatMax | x, y | NaN-ignoring maximum | A NaN operand returns the other one; ties return y |
floatMin | x, y | NaN-ignoring minimum | A NaN operand returns the other one; ties return y |
floatClamp | value, minimum, maximum | floatMin(floatMax(f32(value), f32(minimum)), f32(maximum)) | NaN value → minimum; reversed bounds → maximum |
Lifecycle
None. Stateless functions with no preparation or instance state.
When to use it
Ports of DaisySP or CHOMPI code whose output must match the firmware bit for bit. For ordinary Maru parameters use @maru/math-range, whose clamp propagates NaN instead.
Limits
- f32 operands:
floatClamp(1 / 3, 0, 1)returnsMath.fround(1 / 3).floatMaxandfloatMinthemselves do not round. - The bounds are not reordered; a reversed pair yields
maximum.