News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Floating-point .5 rounding

Started by akko, May 13, 2007, 11:33:29 AM

Previous topic - Next topic

akko

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);
}

Pelle

It appears to be somewhat silly, but correct. Too many changes, so it will not be fixed until the next version.
/Pelle

akko

"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