Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Clamp Value Within Range
Constrain a numeric value between minimum and maximum boundaries.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Math & Numbers). Copy the parameterized template or run the self-contained example.
- 1Category: Math & Numbers
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to clamp val minLimit maxLimit
if val is less than minLimit
return minLimit
.
if val is greater than maxLimit
return maxLimit
.
return val
.
to clamp val minLimit maxLimit
if val is less than minLimit
return minLimit
.
if val is greater than maxLimit
return maxLimit
.
return val
.
c1 is clamp 150 0 100
negVal is 0 minus 10
c2 is clamp negVal 0 100
c3 is clamp 50 0 100
say "Clamped:" c1 c2 c3
if c1 is not 100
fail with "clamp upper bound mismatch: expected 100"
.
if c2 is not 0
fail with "clamp lower bound mismatch: expected 0"
.
if c3 is not 50
fail with "clamp middle value mismatch: expected 50"
.
Installation & Usage
otter snippet inspect math-clamp
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.