0

How do I disable fast math for a function defined in header file or for the entire source file?

#pragma GCC optimize ("no-fast-math")

Adding the line above to both (source file and header file) doesn't seem to work in this case.

4
  • Note: Doing stuff like this in a header will infect all files that include the header. That can be an extremely nasty shock for the unwary. Commented May 21, 2020 at 19:40
  • The approach should be correct - godbolt.org/z/aTEmGQ. You should try to create minimal reproducible example and specify compiler version, command line arguments and why it seems does not working.
    – dewaffled
    Commented May 21, 2020 at 20:26
  • And it is indeed much safer to use such pragmas in combination with GCC push_options and GCC pop_options to always restore previous behavior so it does not suddenly change depending on included files and the include order.
    – dewaffled
    Commented May 21, 2020 at 20:30
  • A piece of code which doesn't work when fast math is enabled can be seen in this question: stackoverflow.com/questions/61938228/…
    – Martin
    Commented May 21, 2020 at 21:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.