This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/15019] New: Float and double math produces unexpected results.
- From: "gcc at paypc dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Apr 2004 02:40:04 -0000
- Subject: [Bug c/15019] New: Float and double math produces unexpected results.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This problem occurs on both gcc-3.2.3 and gcc-3.3.3
For the gcc-3.2.3 compiler:
Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --prefix=/usr --enable-shared
--enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld
--verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.2.3
For the gcc-3.3.3 compiler:
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
Configured with: ./configure --program-suffix=-3.3 --enable-languages=c,c++
--with-system-zlib --enable-threads --prefix=/usr
Thread model: posix
gcc version 3.3.3
On both systems GLIBC 2.3.2 is being used.
Code which triggers the bug:
build command line: gcc -o bugs bugs.c -lm
---------- SNIP -----------
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
float myfloat = 0.001;
double mydouble = 0.0001;
printf("==== dB Printout ====\nFloat: % .5f (% .1f dB) -- Double: % .5f (% .1f
dB)\n", myfloat, log10f(myfloat)*10.0, mydouble, log10(mydouble)*10.0);
printf("==== B Printout ====\nFloat: % .5f (% .1f B) -- Double: % .5f (% .1f
B)\n", myfloat, log10f(myfloat), mydouble, log10(mydouble));
}
---------- SNIP -----------
Output produced:
==== dB Printout ====
Float: 0.00100 ( 10752580800.0 dB) -- Double: 0.00010 ( 125760.0 dB)
==== B Printout ====
Float: 0.00100
(-9073737388866367603040942298049721307647176680268405669064496879808260350778408368798593112776285209317055458675661852075962312342200835280061159040530765214192402488102355092477628744792158548183167207997440.0
B) -- Double: 0.00000 ( 2.1 B)
This seems completely wrong. Why does multiplying the result of log10() by 10.0
completely trash the value, for example?
=MB=
--
Summary: Float and double math produces unexpected results.
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc at paypc dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-slackware-linux
GCC host triplet: i486-slackware-linux
GCC target triplet: i486-slackware-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15019