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

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


Ulrich Drepper <drepper@redhat.com> writes:

> Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
> 
> > I'm pretty sure one does want exp(-Inf) to be zero, not NaN, although
> > I don't know whether it is in the IEEE standard. The problem can be
> > traced to the subtraction of two infinities in the inline math code.
> 
> Well, this is not a bug, it's a feature.  The inline versions of the
> math functions are known to not provide the correct results in all
> cases.  This is not what they are meant for. They are used for
> ordinary computations where speed is more important then precision (or
> boundary cases).  If you need accuracy and correct hanlding of the
> boundary cases you should compile the sources with __NO_MATH_INLINES
> defined.  This will prevent the definition of the inline functions.

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. Taking
exp(-Inf) is a condition that happens quite frequently in technical
codes and people writing such code generally *will* turn on
optimization for everything. You are effectively saying that they
should all run with specially hacked include files for Intel.

Besides, we've given you the patch for fixing this with a quite small
penalty. Are you afraid of benchmarks? You could just remove the guard
code at the highest -O levels.

> For glibc 2.2 we will make it a bit more fool-proof.  We will enable
> the functions which are not 100% accurate only if the user selects the
> -ffast-math option of the compiler.  For now you'll have to use the
> above macro.

[Cc-ed to bug-gcc in case they want to change the definition of
optimizer levels]

-- 
   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