NO

Author Topic: Floating-point .5 rounding  (Read 3091 times)

akko

  • Guest
Floating-point .5 rounding
« 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);
}

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Floating-point .5 rounding
« Reply #1 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.
/Pelle

akko

  • Guest
Re: Floating-point .5 rounding
« Reply #2 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