I'm normally good at googling stuff like this but I can't seem to find anything this time.
I downloaded some source code from here and it uses a function called roundf
.
I already have #include <math.h>
and as a first thought added #include <cmath>
but still have the problem. I can't seem to find out where the function originates...
Is there an alternative function? Or does anyone know where it comes from so I can include the header file?
The roundf()
function is defined by C99, but MSVC implements very little of C99, so it is not available with the Microsoft compilers.
You can use this one:
float roundf(float x)
{
return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
}
You also can use a boost library:
#include <boost/math/special_functions/round.hpp>
const double a = boost::math::round(3.45); // = 3.0
const int b = boost::math::iround(3.45); // = 3
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