Map range: Difference between revisions
Added Easylang
m (→{{header|RPL}}) |
(Added Easylang) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1,088:
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">define a1 = 0, b1 = 0, a2 = 0, b2 = 0
define fn (maprange) as b1 + ( s - a1 ) * ( b2 - b1 ) / ( a2 - a1 )▼
let s = i
Line 1,098 ⟶ 1,097:
let b2 = 0
print i, " : ", b1 + (
▲ let i = i + 1
{{out| Output}}<pre>0 : -1
1 : -0.9000
2 : -0.8000
3 : -0.7000
▲end</syntaxhighlight>
4 : -0.6000
5 : -0.5000
6 : -0.4000
7 : -0.3000
8 : -0.2000
9 : -0.1000
10 : 0</pre>
=={{header|D}}==
Line 1,134 ⟶ 1,140:
=={{header|Delphi}}==
See [[#Pascal]].
=={{header|EasyLang}}==
<syntaxhighlight>
func map_range a1 a2 b1 b2 s .
.
for i = 0 to 10
print i & " -> " & map_range 0 10 -1 0 i
.
</syntaxhighlight>
{{out}}
<pre>
0 -> -1
1 -> -0.90
2 -> -0.80
3 -> -0.70
4 -> -0.60
5 -> -0.50
6 -> -0.40
7 -> -0.30
8 -> -0.20
9 -> -0.10
10 -> 0
</pre>
=={{header|EchoLisp}}==
EchoLisp provides several native interpolation functions: smoothstep, s-curve, .. and '''linear''' which performs linear interpolation.
Line 3,123 ⟶ 3,153:
</pre>
===Basic RPL code===
No specific data structure, no local
≪ SWAP 3 PICK -
SWAP 5 PICK - *
Line 3,582 ⟶ 3,612:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
var mapRange = Fn.new { |a, b, s| b.from + (s - a.from) * (b.to - b.from) / (a.to - a.from) }
Line 3,590 ⟶ 3,620:
for (s in a) {
var t = mapRange.call(a, b, s)
}</syntaxhighlight>
|