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
  • 118,144
  • 57
  • 340
  • 684
Matthias
  • 4,481
  • 12
  • 45
  • 84

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,617
  • 5
  • 48
  • 62
-3

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

phuclv
  • 37,963
  • 15
  • 156
  • 475
tim18
  • 580
  • 1
  • 4
  • 8
  • 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