Anonymous user
Map range: Difference between revisions
Updated to work with Nim 1.4: added missing parameter type. Replaced "strutils" by "strformat". Improved output.
(added →{{header|ReScript}}) |
(Updated to work with Nim 1.4: added missing parameter type. Replaced "strutils" by "strformat". Improved output.) |
||
Line 1,929:
{{trans|Python}}
<lang nim>import
type FloatRange = tuple[s,e: float]
proc mapRange(a, b: FloatRange
b.s + (s - a.s) * (b.e - b.s) / (a.e - a.s)
for i in 0..10:
let m = mapRange((0.0,10.0), (-1.0, 0.0), float(i))
echo &"{i
{{out}}
<pre> 0 maps to -1.0
1 maps to -0.9
2 maps to -0.8
3 maps to -0.7
4 maps to -0.6
5 maps to -0.5
6 maps to -0.4
7 maps to -0.3
8 maps to -0.2
9 maps to -0.1
10 maps to 0.0</pre>
=={{header|Objeck}}==
|