You do not lose accuracy with -ffast-math . This only affects the processing of NaN , Inf , etc. And the order of operations.
If you have a specific piece of code in which you do not want GCC to reorder or simplify calculations, you can mark the variables as used with the asm statement.
For example, the following code performs a rounding operation on f . However, the two operations f += g and f -= g are likely to be optimized by gcc:
static double moo(double f, double g) { g *= 4503599627370496.0;
On x86_64, you can use this asm statement to asm GCC not to perform this optimization:
static double moo(double f, double g) { g *= 4503599627370496.0;
You will need to adapt this for each architecture, unfortunately. In PowerPC, use +f instead of +x .
source share