This helper approximates any given function with a piecewise-linear approximation.
It is assumed that we’re operating in fixed-precision arithmetic with precision bits after point.
We’re approximating the function on the segment [left, right], using 2 ** config.log_buckets equally-distanced control points.
Note that the function has to be defined everywhere, even outside the segment.
Behavior outside of the segment is determined by config.flatten_left and config.flatten_right (they control whether it will be approximated with a constant or linearly).