Interpolate from one range to another

#include <iostream> using namespace std; /* as seen in pressure.js */ double interpolate_from_one_range_to_another(double x, double in_min, double in_max, double out_min, double out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } int main() { cout << interpolate_from_one_range_to_another(-5.0, -5.0, 7.0, 4.0, 12.0) << endl; // 4 cout << interpolate_from_one_range_to_another(2.0, -5.0, 7.0, 4.0, 12.0) << endl; // 8.66667 cout << interpolate_from_one_range_to_another(7.0, -5.0, 7.0, 4.0, 12.0) << endl; // 12 return 0; }