Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

@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

NameInputsOutputDomain as coded
clampvalue, minimum, maximuminclusive boundNaN value or bound → NaN; ±Infinity lands on the nearest bound; reversed bounds return maximum
clampUnitvalueclamp(value, 0, 1)NaN stays NaN; −0 → 0
isFiniteNumbervaluebooleanfalse for NaN and ±Infinity, without Number.isFinite
clampFinitevalue, minimum, maximum, fallback = minimumclamp of value, or of fallback when value is not finiteThe fallback is clamped too
clampFiniteWithFallbacksame, fallback requiredsameExplicit 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

  • clamp propagates NaN. Only clampFinite and clampFiniteWithFallback substitute; a NaN bound still yields NaN from them.
  • Signed zero follows the min/max order: clamp(-0, 0, 1) is +0 and clamp(0, -1, -0) is −0.
  • clampFinite's default argument is not in the realtime call graph; restricted callers use clampFiniteWithFallback.
  • Some leaves use their own conditional clamp instead, which passes NaN through unchanged, and @maru/math-float-clamp ignores NaN like C fmin/fmax.

Algorithm properties and proofs

Lean 4 checks specific properties of this algorithm’s mathematical model. Each model result applies within its stated domain and assumptions.

5 Lean 4 results: 4 proofs in exact arithmetic; 1 counterexample.

Counterexample.The clamp in filters/biquad.ts keeps -0 with bounds [0, 1], while the clamp in math/range.ts gives +0.one concrete binary64 input, compared by bits
Limits and assumptions
  • One input; whether either difference is reachable or audible in a module is not shown.
Theorem
IrToLean.Proof.clamps_disagree_on_negative_zero
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Proved in exact arithmetic.Nested minimum/maximum and the conditional clamp agree over exact values when the bounds are ordered.Exact rationals; ordered finite bounds and stated coefficient guards
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. Exact rational arithmetic only: IEEE rounding, overflow, NaN, infinities and signed-zero behavior are not proved. Sampler mappings cover the named shared stage only. No optimization is enabled or claimed faster.
Theorem
MaruLean.LeafContracts.minmax_clamp_eq
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Proved in exact arithmetic.Clamping places every exact value inside its ordered inclusive bounds.Exact rationals; ordered finite bounds and stated coefficient guards
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. Exact rational arithmetic only: IEEE rounding, overflow, NaN, infinities and signed-zero behavior are not proved. Sampler mappings cover the named shared stage only. No optimization is enabled or claimed faster.
Theorem
MaruLean.LeafContracts.clamp_bounded
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Show 2 more Lean 4 results
Proved in exact arithmetic.An exact value already inside the clamp interval is unchanged.Exact rationals; ordered finite bounds and stated coefficient guards
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. Exact rational arithmetic only: IEEE rounding, overflow, NaN, infinities and signed-zero behavior are not proved. Sampler mappings cover the named shared stage only. No optimization is enabled or claimed faster.
Theorem
MaruLean.LeafContracts.clamp_fixed
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Proved in exact arithmetic.Clamping an exact value twice gives the same result as clamping it once.Exact rationals; ordered finite bounds and stated coefficient guards
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. Exact rational arithmetic only: IEEE rounding, overflow, NaN, infinities and signed-zero behavior are not proved. Sampler mappings cover the named shared stage only. No optimization is enabled or claimed faster.
Theorem
MaruLean.LeafContracts.clamp_idempotent
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Explore proofs alongside performance

Dependencies

None: this node imports no other node.

Dependents

Used by