Why is -freciprocal-math unsafe in GCC?

吃可爱长大的小学妹 提交于 2020-01-03 07:32:14

问题


-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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!