We know that points X1 and X2 have corresponding points Y1 and Y2, so we can calculate Y for any X with:
X - X1 Y - Y1
------- = -------
X2 - X1 Y2 - Y1
From simple formula (A) you can get:
Y = (X - X1) * (Y2 - Y1) / (X2 - X1) + Y1;
This should be mathematically equivalent (B):
Y = (X - X1) / (X2 - X1) * (Y2 - Y1) + Y1;
For an integer mathematical formula, A works better as long as the result of the multiplication (X - X1) * (Y2 - Y1)remains in the range of type. Formula B will not work, because if X1 <= X <= X2, then division will always be equal 0.
For floating point, both should work, but I think B will offer better accuracy since the result of multiplication will be less.
, IEEE 754.
1: , .
2: FP , NaN Infs .