Map range: Difference between revisions
Content added Content deleted
(Frink) |
|||
Line 1,333: | Line 1,333: | ||
</pre> |
</pre> |
||
=={{header|Frink}}== |
|||
Frink can exactly map to rational numbers so the mapping is round-trippable. |
|||
<lang frink>mapRange[s, a1, a2, b1, b2] := b1 + (s-a1)(b2-b1)/(a2-a1) |
|||
for a = 0 to 10 |
|||
println["$a\t" + mapRange[a, 0, 10, -1, 0]]</lang> |
|||
{{out}} |
|||
<pre> |
|||
0 -1 |
|||
1 -9/10 (exactly -0.9) |
|||
2 -4/5 (exactly -0.8) |
|||
3 -7/10 (exactly -0.7) |
|||
4 -3/5 (exactly -0.6) |
|||
5 -1/2 (exactly -0.5) |
|||
6 -2/5 (exactly -0.4) |
|||
7 -3/10 (exactly -0.3) |
|||
8 -1/5 (exactly -0.2) |
|||
9 -1/10 (exactly -0.1) |
|||
10 0 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |