IEEE specifies round-halfway-to-even. However Pelles C seems to follow 5/4 rounding.
GCC and DMC work as specified.
/* Test rint */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <fenv.h>
int main()
{ fesetround(FE_TONEAREST);
printf("You should see 2 : %f\n",rint(1.5));
printf("You should see 2 : %f\n",rint(2.5)); /* Pelles C -> 3 */
printf("You should see 4 : %f\n",rint(3.5));
return(0);
}
It appears to be somewhat silly, but correct. Too many changes, so it will not be fixed until the next version.
"Silly" was my first thought too. But it makes perfect sense to minimize statistic round-off errors. The rounding method is sometimes called "banker's rounding".
Andreas