Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Map Range (Scale Values)
Re-map a number from an incoming range into an outgoing target range.
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 mapRange val inMin inMax outMin outMax
inSpan is inMax minus inMin
outSpan is outMax minus outMin
valDelta is val minus inMin
fraction is valDelta divided by inSpan
scaled is fraction times outSpan
return outMin plus scaled
.
to mapRange val inMin inMax outMin outMax
inSpan is inMax minus inMin
outSpan is outMax minus outMin
valDelta is val minus inMin
fraction is valDelta divided by inSpan
scaled is fraction times outSpan
return outMin plus scaled
.
res is mapRange 75 0 100 0 1
say "Percentage to fraction:" res
if res is not 0.75
fail with "mapRange calculation mismatch: expected 0.75"
.
Installation & Usage
otter snippet inspect math-map-range
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.