Map range: Difference between revisions

→‎{{header|Euphoria}}: Euphoria example added
(Added Nemerle)
(→‎{{header|Euphoria}}: Euphoria example added)
Line 228:
B1 + (S - A1) * (B2 - B1) / (A2 - A1).
</lang>
 
=={{header|Euphoria}}==
<lang euphoria>function map_range(sequence a, sequence b, atom s)
return b[1]+(s-a[1])*(b[2]-b[1])/(a[2]-a[1])
end function
 
for i = 0 to 10 do
printf(1, "%2g maps to %4g\n", {i, map_range({0,10},{-1,0},i)})
end for</lang>
 
Output:
<pre> 0 maps to -1
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
</pre>
 
=={{header|Fantom}}==
Anonymous user