rint -lm function broke

Robert Thomas thoma041@info.census.gov
Thu Sep 14 10:16:00 GMT 2000


> > 	rint under gcc rounds down if the major part is even and the
> > minor is exactly 5, rounds correctly if the major part is odd.
> 
> I.e., it rounds correctly in both cases.  Anyway, this has nothing to
> do with GCC.  GCC is just a compiler, it uses whatever C library is
> available in the OS on which it is running.

	Why do you think it rounds correctly in both cases, did you try
it?  2.5 should round to 3, not 2 just as 3.5 rounds to 4.  Here is  
another example:

Script started on Thu Sep 14 13:02:08 2000
$ cat test7.c
#include <math.h>

main () {
  double num,res;

  num = 2.5;
  res = rint (num);
  printf ("%lf\n",res);
  num = 3.5;
  res = rint (num);
  printf ("%lf\n",res);
}
$ gcc -o test7 test7.c -lm
$ ./test7
2.000000
4.000000
$ exit

script done on Thu Sep 14 13:02:24 2000

I did do some more research, as it turns out this code is broke under the
sun compiler as well.  Apparently in the previous example, it folded the
result of the rint in the returned - if statement to an integer and it did
it correctly.  I know because if I assign a double to the result inside of
that if, it bombs with a assignment error.

I still think it is a code generation problem and not a hardware problem
though.

-Robert




More information about the Gcc-bugs mailing list