Search code examples
visual-c++-2012

round function cannot be found in Win32 C++ project even with cmath include


I created a blank Win32 C++ project. The compiler keeps on giving C3861 undefined error for the round function even if I include the math.h or cmath library.

I have tried the following

1. adding the /TC compile as C++ and using cmath
2. adding the include _MATH_DEFINES_DEFINED 

Solution

  • Visual Studio 2012 (MSVC 11.0) doesn't strictly follow C++11, so it may be that it doesn't have std::round.

    Use

    inline double round(double value) { return value < 0 ? -std::floor(0.5 - value) : std::floor(0.5 + value); }
    // analogously for float