2013-04-10 21:29:02 -07:00
|
|
|
double mapRange(in double[] a, in double[] b, in double s)
|
2015-02-20 00:35:01 -05:00
|
|
|
pure nothrow @nogc {
|
|
|
|
|
return b[0] + ((s - a[0]) * (b[1] - b[0]) / (a[1] - a[0]));
|
2013-04-10 21:29:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() {
|
2015-02-20 00:35:01 -05:00
|
|
|
import std.stdio;
|
|
|
|
|
|
|
|
|
|
immutable r1 = [0.0, 10.0];
|
|
|
|
|
immutable r2 = [-1.0, 0.0];
|
|
|
|
|
foreach (immutable s; 0 .. 11)
|
2013-04-10 21:29:02 -07:00
|
|
|
writefln("%2d maps to %5.2f", s, mapRange(r1, r2, s));
|
|
|
|
|
}
|