gccvisual-studio-2013compiler-optimizationfast-math

Is there a -ffast-math flag equivalent for the Visual Studio C++ compiler


I'm working with the default C++ compiler (I guess it's called the "Visual Studio C++ compiler") that comes with Visual Studio 2013 with the flag /Ox (Full Optimization). Due to floating point side effects, I must disable the -ffast-math flag when using the gcc compiler. Is there an equivalent option for this flag in the configuration of the Visual Studio C++ compiler?


Solution

  • You are looking for /fp:precise, although that is also the default.

    If you need the strictest floating point calculations that VS can offer, try /fp:strict, although that is probably overkill.

    You probably have nothing to worry about since the default behavior should be what you desire. Just make sure that /fp:fast is not specified, but if you try to compile with both /fp:fast and /fp:precise you will get a compilation error anyway, so that should be easy to catch.

    The link that Hans Passant provided to the MSDN website provides all the details you might want.