squiggle/src/utility/lib/Functions.re

14 lines
587 B
ReasonML
Raw Normal View History

2020-02-21 13:54:39 +00:00
let interpolate =
(xMin: float, xMax: float, yMin: float, yMax: float, xIntended: float)
: float => {
let minProportion = (xMax -. xIntended) /. (xMax -. xMin);
let maxProportion = (xIntended -. xMin) /. (xMax -. xMin);
yMin *. minProportion +. yMax *. maxProportion;
};
2020-02-21 14:05:42 +00:00
/* https://bucklescript.github.io/bucklescript/api/Belt.html */
let sum = Belt.Array.reduce(_, 0., (i, j) => i +. j);
let mean = a => sum(a) /. (Array.length(a) |> float_of_int);
let min = Belt.Array.reduce(_, 0., (i, j) => i < j ? i : j);
let max = Belt.Array.reduce(_, 0., (i, j) => i > j ? i : j);