问题
-freciprocal-math
in GCC changes the following code
double a = b / c;
to
double tmp = 1/c;
double a = b * tmp;
In GCC manual, it's said that such an optimization is unsafe and is not sticked to IEEE standards. But I cannot think of an example. Could you give an example about this?
回答1:
Dividing by 10 and multiplying by 0.1000000000000000055511151231257827021181583404541015625 are not the same thing.
回答2:
Perhaps I am thinking of a different compiler flag, but ...
Some processors have instructions for calculating the approximate reciprocal. RCPSS om the x86 (SIMD instruction) comes to mind; it has a relative error 1.5 ∗ 2^−12. Using that flag may allow the compiler to select an approx reciprocal instruction, which might not be a safe thing to do depending upon your application.
Hope this helps.
来源:https://stackoverflow.com/questions/10679154/why-is-freciprocal-math-unsafe-in-gcc