fmaxf, fminf, fmax, fmin, fmaxl, fminl gives corrupted values.
Murakami Hiroshi
dm@tmca.ac.jp
Wed Jan 7 14:34:00 GMT 2004
Dear, GCC bugs,
I believe I found the bug in gcc or libm.a on Linux.
(Althought this may not be the GNU's bug.)
It seems the bug reproduces on most Linux when the cc (gcc) is used.
The bug does not occur with the intel C++ comiler.
In below the sample log is taken on Vine Linux 2.6,
however the bug is also on RedHat8.0.
The symptom is that values of the mathematical functions
fmaxf, fminf, fmax, fmin, fmaxl, fminl are all wrong.
This makes the results of some numerical computations junks.
Please read in below. (Sorry, if this bug were already been known.)
Hiroshi Murakami<dm@tmca.ac.jp>
---------------------------------------
OS information:
Vine Linux 2.6r3 (La Fleur de Bouard)
Kernel 2.4.22-0vl2.8 on an i686
glibc-2.2.4-14vl15
Intel C compiler:
intel-icc7-7.1-37: Intel(R) C++ Compiler for 32-bit applications,
Version 7.1 Build 20031122Z
gcc compiler:
gcc version 2.95.3 20010315 (release)
$
$
$ cc a.c -lm # This is cc(gcc) compiler. The output is broken.
$ ./a.out
sizeof(float)=4
fmaxf(1.23457,6.78901)=12288.00000
fminf(1.23457,6.78901)=10496.00000
sizeof(double)=8
fmax(1.2345678901,6.7890123457)=8448.0000000000
fmin(1.2345678901,6.7890123457)=6144.0000000000
sizeof(long double)=12
fmaxl(1.23456789012345678899,6.78901234567890123463)=4352.00000000000000000000
fminl(1.23456789012345678899,6.78901234567890123463)=2048.00000000000000000000
$
$ icc a.c # This is intel C++ compiler. The output is correct.
$
$ ./a.out
sizeof(float)=4
fmaxf(1.23457,6.78901)=6.78901
fminf(1.23457,6.78901)=1.23457
sizeof(double)=8
fmax(1.2345678901,6.7890123457)=6.7890123457
fmin(1.2345678901,6.7890123457)=1.2345678901
sizeof(long double)=12
fmaxl(1.23456789012345678899,6.78901234567890123463)=6.78901234567890123463
fminl(1.23456789012345678899,6.78901234567890123463)=1.23456789012345678899
$
$
$
$ cat a.c # This shows the source code for this test.
/////////////////////////////////////////////////////////////////
//
// This is the bug sample C source code.
//
#include <stdio.h>
#include <math.h>
main()
{
float xf,yf,zf;
double xd,yd,zd;
long double xl,yl,zl;
//
// check fmaxf, fminf;
//
printf("sizeof(float)=%d\n",sizeof(float));
xf=1.2345678901234567890F; yf=6.7890123456789012345F;
zf=fmaxf(xf,yf); printf("fmaxf(%.5f,%.5f)=%.5f\n",xf,yf,zf);
zf=fminf(xf,yf); printf("fminf(%.5f,%.5f)=%.5f\n",xf,yf,zf);
//
// check fmax, fmin;
//
printf("sizeof(double)=%d\n",sizeof(double));
xd=1.2345678901234567890; yd=6.7890123456789012345;
zd=fmax(xd,yd); printf("fmax(%.10lf,%.10lf)=%.10lf\n",xd,yd,zd);
zd=fmin(xd,yd); printf("fmin(%.10lf,%.10lf)=%.10lf\n",xd,yd,zd);
//
// check fmaxl, fminl;
//
printf("sizeof(long double)=%d\n",sizeof(long double));
xl=1.2345678901234567890L; yl=6.7890123456789012345L;
zl=fmaxl(xl,yl); printf("fmaxl(%.20Lf,%.20Lf)=%.20Lf\n",xl,yl,zl);
zl=fminl(xl,yl); printf("fminl(%.20Lf,%.20Lf)=%.20Lf\n",xl,yl,zl);
//
}
/////////////////////////////////////////////////////////////////
$ exit
More information about the Gcc-bugs
mailing list