define this function inside interpolate_1d (as its used locally just there)