My 50 cents for this:
1) No, explained further in 3.
2) I do not know any formula, so I just skip this one.
3) The rule of the thumb that I know is to try to perform operations between operands with a close order of magnitude.
A practical example:
You want to divide by 1.000.000 the number 63.000.000.
Using the first approach, you will eventually divide 63 * 10 ^ 6 into 1 * 10 ^ 6, which have very close values.
However, if you use the second approach, then
temp = 1.0f / x;
Will produce 10 ^ (- 6).
Now the multiplication of 63 * 10 ^ 6 * 10 ^ (- 6) will lead to significant losses in accuracy, because the difference between them is large. The CPU will try to use the exponential notation + fraction of the number 10 ^ 6 to represent the number 10 ^ (- 6) ...
A viable alternative would be for temp to be
temp = 1 / 1.000;
And then
a = a * temp * temp ;
As the magnitude is closer, there is less likelihood of precession loss.
MichaelCMS
source share