// More accuarte #include <math.h> double round(double d) { return floor(d + 0.5); } double slope = 1.0 * (output_end - output_start) / (input_end - input_start); double output = output_start + round(slope * (input - input_start));