This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug math/3976] New: libm rounding modes do not work correctly for many archs
- From: "madcoder at debian dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 6 Feb 2007 13:14:15 -0000
- Subject: [Bug math/3976] New: libm rounding modes do not work correctly for many archs
- Reply-to: sourceware-bugzilla at sourceware dot org
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.