F.9.6.6 The round functions
round((+-)0) returns (+-)0.
round((+-)(inf)) returns (+-)(inf).
The double version of round behaves as though implemented by
#include <math.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
double round(double x)
{
double result;
fenv_t save_env;
feholdexcept(&save_env);
result = rint(x);
if (fetestexcept(FE_INEXACT)) {
fesetround(FE_TOWARDZERO);
result = rint(copysign(0.5 + fabs(x), x));
}
feupdateenv(&save_env);
return result;
}
The round functions may, but are not required to, raise the “inexact” floating-point exception for non-integer numeric arguments, as this implementation does.