11

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?

einpoklum
  • 86,754
  • 39
  • 223
  • 453
Matthias
  • 3,833
  • 11
  • 36
  • 74

2 Answers2

13

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.

pattivacek
  • 5,016
  • 4
  • 46
  • 57
-3

None of the MSVC++ options enable the optimizations which are invoked by g++ -ffast-math.

phuclv
  • 27,258
  • 11
  • 104
  • 360
tim18
  • 530
  • 1
  • 4
  • 7
  • 1
    are you sure? how about `/fp:`? – phuclv Oct 25 '16 at 07:00
  • Microsoft /fp:fast doesn't invoke those optimizations. You may be confused by the conflicting Intel C++ usage where fast=2 does operate similar to g++ -ffast-math ( and fast=1 invokes the important ones, except for complex limited range). – tim18 Jul 20 '17 at 17:45
  • obviously it may not be exactly the same but it does specify the floating-point operations behavior **which is what the OP asked**. He didn't ask about all `-ffast-math` side effects – phuclv Jul 21 '17 at 01:01
  • Does `-ffast-math` included in `-O3` in GCC? Because it seems in my project ([Image Convolution](https://github.com/RoyiAvital/Projects/tree/master/ImageConvolution)) that MSVC 2015 generate much faster code than GCC 7.1. – Royi Aug 05 '17 at 10:01
  • No,. -O3 doesn't set -ffast-math. – tim18 Aug 05 '17 at 10:20