Inline version [x86] of exp is buggy, exp(-Inf) should be zero.

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
Fri May 5 02:09:00 GMT 2000


Mike Stump <mrs@windriver.com> writes:

> > To: drepper@cygnus.com (Ulrich Drepper)
> > From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
> > Date: 05 May 2000 09:41:11 +0200
> 
> > > The inline versions of the math functions are known to not provide
> > > the correct results in all cases.
> 
> > This is quite shocking! If that is your attitude to inline
> > functions, I do not think they have any business being included at
> > compiler levels below -O3 and they are getting turned on already at
> > -O.
> 
> > [Cc-ed to bug-gcc in case they want to change the definition of
> > optimizer levels]
> 
> The -O flags are never used to perform semantic selections that differ
> from mandated behaviors.  Some compilers (I mean other than gcc) in
> the past may have done this, but they were wrong.  The -ffast-math
> option is exactly the right way.  -mieee might also be taken as hint
> on how to compute things.

That policy makes good sense to me, but currently -O *does* create a
difference from mandated behaviors, with or without -mieee, e.g. (with
egcs 2.91.66 as supplied with latest RedHat, so slightly different
option name):

$ gcc -mieee-fp glibc-bug.c -lm && ./a.out
0
$ gcc -O -mieee-fp glibc-bug.c -lm && ./a.out
nan

So this is a bug (in glibc), yes?


$ cat glibc-bug.c
#include<stdio.h>
#include<math.h>
main(){
        volatile double neginf = -1./0.;
        printf("%g\n", exp(neginf));
}

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


More information about the Gcc-bugs mailing list