public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/763] New: On AMD64 in IEEE round-to-plus-infinity (upward) mode, pow() may segfault and exp() yield negative results
@ 2005-02-24 17:19 David dot Monniaux at ens dot fr
  2005-02-24 17:20 ` [Bug libc/763] " David dot Monniaux at ens dot fr
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: David dot Monniaux at ens dot fr @ 2005-02-24 17:19 UTC (permalink / raw)
  To: glibc-bugs

On AMD64, after a fesetround(FE_UPWARD), on certain values:
- pow() issues a segmentation fault
- exp() yields a negative result

#include <math.h>
#include <fenv.h>
#include <stdio.h>
 
int main()
{
  double x = 79.252413924118542354335659183561801910400390625;
  double y = 0.333333299999999999041477849459624849259853363037109375;
  double z;
  fesetround(FE_UPWARD);
  z = pow(x,y); /* segfault my_log2 () */
  return 0;
}

#include <math.h>
#include <fenv.h>
#include <stdio.h>
 
int main()
{
  double x = 79.252413924118542354335659183561801910400390625;
  double y = 0.333333299999999999041477849459624849259853363037109375;
  double z;
  double a = 10e18;
  double b = 1.0;
  fesetround(FE_UPWARD);
  z = exp(log(x)*y);
  printf("%lf %lf\n", (a+b)-a, z); /* second number output is -0.246008 */
  return 0;
}

I note that ./sysdeps/ieee754/dbl-64/e_pow.c states
"Assumption: Machine arithmetic operations are performed in round to nearest
mode of IEEE 754 standard."

Proposed fix: if glibc does not attempt to provide the nearest upward or
downward result for pow() and exp() in non-nearest rounding modes, one can use
the exp2() and log2() primitives.

ex: pow(x, y) = exp2(log2(x) * y)

-- 
           Summary: On AMD64 in IEEE round-to-plus-infinity (upward) mode,
                    pow() may segfault and exp() yield negative results
           Product: glibc
           Version: 2.3.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: David dot Monniaux at ens dot fr
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://sources.redhat.com/bugzilla/show_bug.cgi?id=763

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-16 12:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-24 17:19 [Bug libc/763] New: On AMD64 in IEEE round-to-plus-infinity (upward) mode, pow() may segfault and exp() yield negative results David dot Monniaux at ens dot fr
2005-02-24 17:20 ` [Bug libc/763] " David dot Monniaux at ens dot fr
2005-02-24 17:21 ` David dot Monniaux at ens dot fr
2005-03-10  9:48 ` [Bug math/763] " gotom at debian dot or dot jp
2005-06-07 11:58 ` David dot Monniaux at ens dot fr
2005-09-16 12:29 ` aj at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).