Clamp
Constrains x to the range [lower, upper].
Wikipedia
Clamp (function)WikidataQ5125465Clamp(x, lower, upper)x if it's already in , else the nearer bound.Clamp(x)x clamped to the default range , Wolfram's Clip[x].Clamp(x, lower, upper, vLower, vUpper)Wolfram's Clip[x, {lower, upper}, {vLower, vUpper}]: a replacement value outside the range, rather than the nearer bound.Typed signatures
| Type | Package | Applies |
|---|---|---|
(real | signed_infinity, real | signed_infinity, real | signed_infinity) -> real | signed_infinity | compute-engine | always |
(any, any?, any?, any?, any?) -> any | combinatoricsreplaces compute-engine | always |
(any, any?, any?, any?, any?) -> any | structuresreplaces combinatorics | always |
Details
- Constrains a value to : below lower it returns lower, above upper it returns upper, otherwise x unchanged.
- A 1-argument defaults to , matching Wolfram's Clip[x].
- Idempotent: clamping an already-clamped value changes nothing.
- Doesn't validate that lower upper; with the bounds swapped it just falls through whichever comparison fires first.