- takes two values x1 and x2.
- returns a a function that
- takes as argument a single number
- return the interpolated value between the two intial values
x1 = 10
x2 = 15
f(x1, x2) = (x2 - x1)*t + x1 = F(t)
F(0.5) = 12.5
import std.stdio; auto interp_proc_maker(float x1, float x2){ float interp(float s) { return (x2-x1)*s+x1;} return &interp;} void main() { auto f1 = interp_proc_maker(10, 15); writefln("f1(0.5) = %f", f1(0.5)); }
$ gdc example.d
$ ./a.out
f1(0.5) = 12.500000
No comments:
Post a Comment