Pelles C forum

Pelles C => Bug reports => Topic started by: akko on May 13, 2007, 11:33:29 AM

Title: Floating-point .5 rounding
Post by: akko on May 13, 2007, 11:33:29 AM
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);
}
Title: Re: Floating-point .5 rounding
Post by: Pelle on June 05, 2007, 09:15:50 AM
It appears to be somewhat silly, but correct. Too many changes, so it will not be fixed until the next version.
Title: Re: Floating-point .5 rounding
Post by: akko on June 10, 2007, 05:32:06 PM
"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