[Bug tree-optimization/114363] inconsistent optimization of pow(x,2)+pow(y,2)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114363 --- Comment #4 from vincenzo Innocente --- Thanks Harald, I missed the point that float z = pow(double(x),2) and float z = x*x would indeed produce exactly the same result, while in all other cases of course not.
[Bug tree-optimization/114363] inconsistent optimization of pow(x,2)+pow(y,2)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114363 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek --- Or use pow(x,2.0f)+pow(y,2.0f). Anyway, see https://eel.is/c++draft/c.math#cmath.syn-3
[Bug tree-optimization/114363] inconsistent optimization of pow(x,2)+pow(y,2)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114363 Xi Ruoyao changed: What|Removed |Added Resolution|--- |INVALID CC||xry111 at gcc dot gnu.org Status|UNCONFIRMED |RESOLVED --- Comment #2 from Xi Ruoyao --- (In reply to Harald van Dijk from comment #1) > This is, I believe, correct. Before C++11, calling std::pow with float and > int arguments, it returned a float. As of C++11, it returns a double. > > If the result of pow(x,2) is immediately converted to float, then it is a > valid optimisation to convert it to x*x: that is guaranteed to produce the > exact same result. But if it isn't, then converting to x*x loses accuracy > and alters the result. Thus invalid. > You can call std::powf instead of std::pow to avoid the promotion to double. Or add -std=c++98.
[Bug tree-optimization/114363] inconsistent optimization of pow(x,2)+pow(y,2)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114363 Harald van Dijk changed: What|Removed |Added CC||harald at gigawatt dot nl --- Comment #1 from Harald van Dijk --- This is, I believe, correct. Before C++11, calling std::pow with float and int arguments, it returned a float. As of C++11, it returns a double. If the result of pow(x,2) is immediately converted to float, then it is a valid optimisation to convert it to x*x: that is guaranteed to produce the exact same result. But if it isn't, then converting to x*x loses accuracy and alters the result. You can call std::powf instead of std::pow to avoid the promotion to double.