public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/3976] New: libm rounding modes do not work correctly for many archs
@ 2007-02-06 13:14 madcoder at debian dot org
  2007-02-06 22:13 ` [Bug math/3976] " madcoder at debian dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 21+ messages in thread
From: madcoder at debian dot org @ 2007-02-06 13:14 UTC (permalink / raw)
  To: glibc-bugs

It seems that changing the rounding modes make some functions (like exp, or 
sin, or ...) buggy on many archs. The testing code is:

===============================================================================
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fenv.h>

static int rnd[4] = { FE_TONEAREST, FE_TOWARDZERO, FE_DOWNWARD, FE_UPWARD };
static char rc[4] = "NZDU";

int main (int argc, char *argv[])
{
  int i;

  for (i = 1; i < argc; i++)
    {
      int r;
      double x;
      char *end;

      x = strtod (argv[i], &end);
      if (*end != '\0')
        exit (EXIT_FAILURE);

      for (r = 0; r < 4; r++)
        {
          double y;

          fesetround (rnd[r]);
          y = exp (x);
          printf ("%c: exp(%.17g) = %.17g\n", rc[r], x, y);
        }
    }

  return 0;
}
===============================================================================

I've checked on my amd64 that it indeed works in 32bits mode (and it also work 
on an i386 machine) but it does not in 64bits mode:

[madcoder mad] gcc -m32 -lm -o a a.c ; ./a 1 2
N: exp(1) = 2.7182818284590451
Z: exp(1) = 2.7182818284590451
D: exp(1) = 2.7182818284590451
U: exp(1) = 2.7182818284590455
N: exp(2) = 7.3890560989306504
Z: exp(2) = 7.3890560989306495
D: exp(2) = 7.3890560989306495
U: exp(2) = 7.3890560989306504

[madcoder mad] gcc -m64 -lm -o a a.c ; ./a 1 2
N: exp(1) = 2.7182818284590451
Z: exp(1) = 2.7182818284590451
D: exp(1) = 2.7182818284590451
U: exp(1) = 0.04788398250919005
N: exp(2) = 7.3890560989306504
Z: exp(2) = 4.0037745305985499
D: exp(2) = 4.0037745305985499
U: exp(2) = 7.3890560989306504

I tested it on other archs, here is the summary:
 - i386, m68k, ia64 have been tested OK.
 - arm: only FE_ROUNDTONEAREST exists (which is ok as per C standard)
 - amd64, mips, ppc, hppa, s390, sparc produce wrong results, in their own 
unique way.

I've not been able to test alpha yet though.

-- 
           Summary: libm rounding modes do not work correctly for many archs
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: aj at suse dot de
        ReportedBy: madcoder at debian dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=3976

------- 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] 21+ messages in thread

end of thread, other threads:[~2014-05-28 19:40 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-3976-131@http.sourceware.org/bugzilla/>
2012-02-29  1:16 ` [Bug math/3976] libm rounding modes do not work correctly for many archs jsm28 at gcc dot gnu.org
2012-02-29  2:35 ` vincent-srcware at vinc17 dot net
2012-02-29  2:54 ` vincent-srcware at vinc17 dot net
2012-03-02 15:17 ` jsm28 at gcc dot gnu.org
2012-03-02 16:05 ` jsm28 at gcc dot gnu.org
2012-03-02 16:09 ` jsm28 at gcc dot gnu.org
2012-03-02 20:56 ` jsm28 at gcc dot gnu.org
2012-03-05 12:27 ` jsm28 at gcc dot gnu.org
2012-03-05 13:34 ` vincent-srcware at vinc17 dot net
2013-01-10 19:23 ` aj at suse dot de
2014-02-16 19:37 ` jackie.rosen at hushmail dot com
2014-05-28 19:40 ` schwab at sourceware dot org
2007-02-06 13:14 [Bug math/3976] New: " madcoder at debian dot org
2007-02-06 22:13 ` [Bug math/3976] " madcoder at debian dot org
2007-05-18 14:46 ` debian-glibc at lists dot debian dot org
2007-09-19 12:55 ` vincent+libc at vinc17 dot org
2008-02-25 13:12 ` vincent+libc at vinc17 dot org
2008-10-27  8:18 ` c_keil at yahoo dot de
2008-10-27  8:26 ` jakub at redhat dot com
2008-10-27  9:34 ` vincent+libc at vinc17 dot org
2008-10-27 12:43 ` joseph at codesourcery dot com
2010-03-21 22:24 ` vincent+libc at vinc17 dot org

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