This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug math/887] Math library function "logb" and "nextafter" inconsistent
- From: "rsa at us dot ibm.com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Thu, 23 Feb 2012 19:48:48 +0000
- Subject: [Bug math/887] Math library function "logb" and "nextafter" inconsistent
- Auto-submitted: auto-generated
- References: <bug-887-131@http.sourceware.org/bugzilla/>
http://sourceware.org/bugzilla/show_bug.cgi?id=887
--- Comment #11 from Ryan S. Arnold <rsa at us dot ibm.com> 2012-02-23 19:48:48 UTC ---
Here's an actual testcase which demonstrates the behavior in logb that's
undesireable:
#include <stdio.h>
#include <math.h>
#include <fenv.h>
#include <float.h>
#define NUM_INPUTS 6
int main() {
double ret;
int i = 0;
typedef union {
long long ll;
double d;
} input;
input inputs[NUM_INPUTS];
inputs[0].ll = 0X3FF0000000000000LL;
inputs[1].ll = 0X3FF8000000000000LL;
inputs[2].ll = 0X3FF2000000000000LL;
inputs[3].ll = 0X3FFFFFFFFFFFFFFFLL;
inputs[4].ll = 0X3FF7FFFFFFFFFFFFLL;
inputs[5].ll = 0X3FF1FFFFFFFFFFFFLL;
for (i=0;i<NUM_INPUTS;i++)
{
printf ("Input: %f\n",inputs[i].d);
fesetround (FE_TONEAREST);
ret = logb (inputs[i].d);
printf ("%f\n",ret);
fesetround (FE_DOWNWARD);
ret = logb (inputs[i].d);
printf ("%f\n",ret);
}
return 0;
}
This doesn't fail on PowerPC64:
~/bugs/GLIBC887/$ vim foo.c
~/bugs/GLIBC887/$ gcc -m64 foo.c -o foo -lm
~/bugs/GLIBC887/$ ./foo
Input: 1.000000
0.000000
0.000000
Input: 1.500000
0.000000
0.000000
Input: 1.125000
0.000000
0.000000
Input: 2.000000
0.000000
0.000000
Input: 1.500000
0.000000
0.000000
Input: 1.125000
0.000000
0.000000
gcc version 4.1.2 20070115 (SUSE Linux)
But it does fail with 32-bit PowerPC:
~/bugs/GLIBC887/$ gcc -m32 foo.c -o foo -lm
~/bugs/GLIBC887/$ ./foo
Input: 1.000000
0.000000
-0.000000
Input: 1.500000
0.000000
-0.000000
Input: 1.125000
0.000000
-0.000000
Input: 2.000000
0.000000
-0.000000
Input: 1.500000
0.000000
-0.000000
Input: 1.125000
0.000000
-0.000000
gcc version 4.1.2 20070115 (SUSE Linux)
libc-2.4.so
I tried a newer compiler and library:
~/bugs/GLIBC887/$ /opt/at4.0/bin/gcc -m32 foo.c -o foo -lm
~/bugs/GLIBC887/$ ./foo
Input: 1.000000
0.000000
0.000000
Input: 1.500000
0.000000
0.000000
Input: 1.125000
0.000000
0.000000
Input: 2.000000
0.000000
0.000000
Input: 1.500000
0.000000
0.000000
Input: 1.125000
0.000000
0.000000
gcc version 4.5.4 20110524 (Advance-Toolchain-4.0-5) [ibm/gcc-4_5-branch
revision 179810] (GCC)
libc-2.12.1.so
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.