On GCC, we enable -ffast-math
to speed up floating point calculations. But as we rely on proper behavior of NaN and Inf floating point values, we also turn on -fno-finite-math-only
, so that optimization which assume values aren't NaN/Inf
For MSVC, the "equivalent" to -ffast-math
is apparently /fp:fast
. However, like GCC's -ffast-math
, it also includes the optimizations which assume that Nan/Inf aren't present. (Critically, is appears tests like std::isnan() aren't guaranteed to give "accurate" results.)
Is there an option for MSVC C++ compilation which allows you to take advantage of most of the /fp:fast
optimizations, but still treats NaN and Inf values "properly"? (Or at the very least, guarantees that tests like std::isnan()/std::isinf() will detect NaN/Inf if they do happen to be generated.)
MSVC is doing the compilation job significantly faster than MinGW-w64. The DLL sizes are comparable, if optimization is set to "-O2" for MinGW-w64, with "-O3" the DLLs from MinGW-w64 are larger. Binary files compiled with MinGW-w64 are performing significantly better than those compiled with MSVC.
Microsoft Visual Studio is a good compiler for developing Windows applications. Although Visual Studio presents a ton of choices to the user when first starting out (for instance, there are a lot of different project types), the amount of choice gives a good idea of the overall scope of this tool.
Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.
You can build C and C++ applications on the command line by using tools that are included in Visual Studio. The Microsoft C++ (MSVC) compiler toolset is also downloadable as a standalone package. You don't need to install the Visual Studio IDE if you don't plan to use it.
guarantees that tests like std::isnan()/std::isinf()
Unlike GCC, MSVC (CL RC 19) doesn't actually optimize out std::isnan
on the /fp:fast
setting:
Another alternative that will never be optimized out is to call the C99 isnan
or the MSVC intrinsic _isnanf
. Or roll your own nan
test against a known bit-mask, which can be generated with std::numeric_limits::quiet_NaN
.
See: https://godbolt.org/g/YdZJq5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With