Map range: Difference between revisions

Content added Content deleted
(Added 11l)
Line 2,431: Line 2,431:
9 maps to -0.1
9 maps to -0.1
10 maps to 0</pre>
10 maps to 0</pre>

=={{header|ReScript}}==
<lang rescript>let map_range = ((a1, a2), (b1, b2), s) => {
b1 +. ((s -. a1) *. (b2 -. b1) /. (a2 -. a1))
}

Js.log("Mapping [0,10] to [-1,0] at intervals of 1:")

for i in 0 to 10 {
Js.log("f(" ++ Js.String.make(i) ++ ") = " ++
Js.String.make(map_range((0.0, 10.0), (-1.0, 0.0), float(i))))
}</lang>

<lang html><!DOCTYPE html>
<html>
<head>
<title>ReScript: Map_range</title>
<meta charset="UTF-8"/>
<style rel="stylesheet" type="text/css">
body { color:#EEE; background-color:#888; }
</style>
<script>var exports = {};</script>
<script src="./maprange.js"></script>
</head>
<body>

</body>
</html></lang>

{{out}}
<pre>
Mapping [0,10] to [-1,0] at intervals of 1:
f(0) = -1
f(1) = -0.9
f(2) = -0.8
f(3) = -0.7
f(4) = -0.6
f(5) = -0.5
f(6) = -0.4
f(7) = -0.30000000000000004
f(8) = -0.19999999999999996
f(9) = -0.09999999999999998
f(10) = 0
</pre>


=={{header|REXX}}==
=={{header|REXX}}==