4 ms·
I am shocked by the plethora of posts by people surprised when -ffast-math breaks their code (no insult to the pspdfkit folks intended). If it were a harmless
by gumby 5y ago
I am shocked by the plethora of posts by people surprised when -ffast-math breaks their code (no insult to the pspdfkit folks intended).
If it were a harmless flag you'd think it would be enabled by default. That's a clue that you should look before you leap.
We have a few files in our code base that compile with -ffast-math but the rest don't. Those files were written with that flag in mind.
- asveikau 5y agoPeople sometimes have unreasonable faith in compilers or libraries. It's a common adage to look at bugs in application code before suspecting these lower layers. That is not the same thing as the lower layers never producing unexpected results. So when people get evidence that a compiler feature may be rough around the edges, they resist it.
- gumby 5y agoFrom Cygnus it felt like the opposite: more than half the reports were from people blaming the compiler when it was their own code that was at fault. But that perspective aside, I agree: generally people correctly assume that their tools are OK and their code is at fault. I wouldn't consider -ffast-math a bug: it's a sharp tool that should only be used by experienced users. If there's a bug at all it's that, in retrospect, the flag should have had a different name.
- Sharlin 5y agoNo, it’s easy to assume (even after reading the documentation) that -ffast-math just makes some calculations less precise or otherwise not strictly IEEE 754 compliant. That would be plenty reason enough not to enable it by default, but make it available for those who desire maximum performance at the expense of precision (or accuracy), as may be a perfectly reasonable tradeoff in cases like computer graphics. It’s very understandable that people are surprised by the fact that -ffast-math can actually break code in unintuitive ways.
- usefulcat 5y agoI was definitely not expecting it to completely break std::isnan and std::isinf.
- gumby 5y agoThe documentation literally says that the results may be incorrect, not to mention documenting that it enables a flag with unsafe in its name. I feel like a lot of programmers just type stuff and assume if it compiles it should ship.