Skip to content
Oakfield Operator Calculus Function Reference Site

Clamping

For bounds aba \le b and scalar xx,

clamp(x;a,b)=min(max(x,a),b)\operatorname{clamp}(x; a,b) = \min(\max(x,a), b)

Domain: real numbers (or componentwise on vectors). Codomain: [a,b][a,b].


Non-expansive: clamp(x;a,b)clamp(y;a,b)xy|\operatorname{clamp}(x;a,b) - \operatorname{clamp}(y;a,b)| \le |x-y|. Piecewise linear and idempotent: applying twice leaves the result unchanged.


When a=a=-\infty or b=b=\infty, clamping reduces to one-sided thresholding. Choosing a=ba=b collapses all inputs to the constant bound.


  • One-sided clamp corresponds to thresholding.
  • a=ba=b yields a constant map.

Soft clamping replaces hard corners with smooth transitions; thresholding is the one-sided variant.


Oakfield uses clamping both as a low-level numeric utility and as part of operator “safety” policies:

  • Warp continuity guards clamp or limit invalid warp-gradient samples via per-operator continuity settings (none|strict|clamped|limited) and clamp_min/clamp_max.
  • Thermostat regulation optionally bounds regulated parameters (e.g. lambda_min/lambda_max, with a smooth clamp option).
  • Integrator safety clamps adaptive timesteps to min_dt/max_dt.
  • Math helpers in core/math_utils.h include sim_clamp_double and magnitude-preserving sim_clamp_complex.

Clamping is the projection of a scalar onto the closed interval [a,b][a,b], a basic operation in constrained optimization and numerical safeguards.

Hard clamps are commonly replaced by smooth clamps when differentiability is required, but the hard version remains a robust safeguard primitive.


  • Boyd & Vandenberghe, Convex Optimization