r/cpp • u/Little-Reflection986 • Feb 16 '26
Favorite optimizations ??
I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!
138
Upvotes
View all comments
Show parent comment
2
u/James20k P2005R0 Feb 17 '26
This is unfortunately a common misconception, its simply not true in C++. C++ doesn't even mandate that floats are ieee
I'd recommend looking up floating point contraction in C++, a lot of people think that C++ gives much stronger guarantees than it actually does
https://godbolt.org/z/hMGbjoWz7
I modified one of the examples from the reproducible floating point paper, without -ffast-math being enabled, the compiler automatically generates an fma, and this results in cross platform divergence. Its completely legal in C++