Beware of Fast-Math
Published on: 2025-06-11 13:05:57
One of my more frequent rants, both online and in person, is the danger posed by the "fast-math" compiler flag. While these rants may elicit resigned acknowledgment from those who already understand the dangers involved, they do little to help those who don't. So given the remarkable paucity of writing on the topic (including the documentation of the compilers themselves), I decided it would make a good inaugural topic for this blog.
It's a compiler flag or option that exists in many languages and compilers, including:
So what does it actually do? Well, as the name said, it makes your math faster. That sounds great, we should definitely do that!
I mean, the whole point of fast-math is trading off speed with correctness. If fast-math was to give always the correct results, it wouldn’t be fast-math, it would be the standard way of doing math.
— Mosè Giordano
The rules of floating point operations are specified in the IEEE 754 standard, which all popular programming languages (mostly
... Read full article.