This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
rint -lm function broke
- To: gcc-bugs at gcc dot gnu dot org
- Subject: rint -lm function broke
- From: Robert Thomas <thoma041 at info dot census dot gov>
- Date: Thu, 14 Sep 2000 11:25:31 -0400 (EDT)
Hello Gnu (Skip narrative goto BUG label on left)
This bug involves the rint function. I have debugged it as far as
as I can and I'm not sure what is wrong without getting an assembler book
to debug the asm.
We are using mysql to render web data and mysql was compiled on a
RH Linux 6.2 box using gcc (and egcs,gcc-2.95.2, it didn't matter). This
error is also reproduceable on a Sun Solaris 2.8 box using gcc and sun's
libm.
BUG:
rint under gcc rounds down if the major part is even and the
minor is exactly 5, rounds correctly if the major part is odd. I really
don't think that this is the actual library rint problem, it seems to be a
gcc problem. Here is some very reproduceable (raw) code to show this and
this was rendered from the actual mysql code eliminating and
simplifying lines for readability:
test1.c
------
#include <math.h>
double Item_func_round(double value, int dec)
{
unsigned int abs_dec=abs(dec);
double tmp=pow(10.0,(double) abs_dec);
return dec < 0 ? rint(value/tmp)*tmp : rint(value*tmp)/tmp;
}
main () {
double num;
int prec;
double result;
while (1) {
scanf ("%lf %d",&num,&prec);
result = Item_func_round (num,prec);
printf ("%lf -> %lf\n",num,result);
}
}
------cut-----
What this is designed to do is to take a number and round it depending on
the integer argument. Negative values round to the left of the decimal,
zero is at the decimal and positive values to the right.
Brillig.ssd.census.gov is a very busy RH linux box (Dell 6300 4X).
[thoma041@brillig test] gcc -o test1 test1.c -lm
[thoma041@brillig test] ./test1
2.5 0
2.500000 -> 2.000000
3.5 0
3.500000 -> 4.000000
info.census.gov is a Sun 250 and the gcc will do the same thing there. If
I compile the same code under /opt/SUNWspro/bin/cc (the new sun forte
compiler), it works as it should. a ldd shows:
test1:
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libdl.so.1 => /usr/lib/libdl.so.1
test1.sun:
libc.so.1 => /usr/lib/libc.so.1
libdl.so.1 => /usr/lib/libdl.so.1
The assembler between the 2 compilers is different enough I didn't want to
speculate on what is wrong for I may lead someone up the wrong path.
-Robert
--------------------------------------------------------------------------
(Signature file)
Robert Thomas, CISSP
FOB-3, Room 1364
Washington, DC 20233
Phone 301-457-2157
No free man shall ever be debarred the use of arms.
-Thomas Jefferson, Proposed Virginia constitution, 1776
gpg (990923)
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.0.0 (SunOS)
Comment: For info see http://www.gnupg.org
mQGiBDfqVZMRBAD1KvKk9CTCxLY17V2kvAxewu0GkXu2wUeuasI61rBLfI+bs+9n
kUSqSzybYMe9ecgemhlWL6R5OEPFiHIutAQ5S8yk+GQZrvNtVQLDAN3ec4T9JCdN
XfMQTuz+KfOVNeFcAgznvTJbmghAxUCHhI5hDa4DylyUyso+dL+vCMUaLwCgkJ9A
6Hvsc5KaSdoXmgexzpNBfWcEAKxBKSD3bEXvKz9xWv8Kgkg93HtFMr3KR6dCWEp4
JHEbLKO4MHEcWekgcmPGCUJQKbOgs9Au3fOrpyRnrCKuN1ff2xMgrcJixXtr0Yri
gnrgNh/0PgdD4ASbVCWeWMX13serxobhUlk/8XSXYgC1ZL3vEo0WI5lWhE+ipJEr
/aTnA/9hzPazh/BuU4AfatYoQ+f+A3u+quCCi/Cy4/ja2CIX2w+viiM8ohbVCm8h
/I4lYkbQjdQWb7QGQo5D2X+xiCybPTIm6mKPeQGgZoT00IkDrf/JOeQkJGEaAEq3
AlcDVTZe4diisRLMhNeZh3yJ/RExNPk7wWrW822ABm1FE+JEgrQjUm9iZXJ0IFRo
b21hcyA8dGhvbWEwNDFAY2Vuc3VzLmdvdj6IWwQTEQIAGwUCN+pVkwUJCWYBgAML
CgMDFQMCAxYCAQIXgAAKCRAGq29utAbt2bgTAJ9iYYtkB2X/BUdJMn9wZl8QubTn
ywCeM/44H2Suh884Y+GZdE3IzUurcDC5Ag0EN+pW4BAIAIp2egQkbWQHfFAX9QL/
/JvWd2up63WimUFA29KdTVlvW7qjvWcXhuSh4YY2akxSxNuEIO1vPWCSs+D6m7bE
Q0WsWiaIwiunB4pqKB97rmILS/TfXECovLqOgjnDxCFUUZoAnb/CbmDskEEN3+AV
eBaVURsPJl98h8RfzJ1uepc+uX2tCT55XTmdT9fyDP0TCB7ggU6eAvv8vE0Cef8k
aaBp54NteaxzcH30FBGhztLliuimea2qpkOj4mYM/6WzR1AlS99mftxfbOiRAKxP
+MwNlkUEX5t7YlfGCzxZ27KmjQ+cvMi7YyvPA2Ojs9ou9E3djhEd+l4CVWuT+JDt
tK8AAwUH/2+PeND+vImQ3XfQAkBi69MezpU4nU4RCVt6d02n9OLIwyjKBkjpsKr3
sygnQIlP82iKg/ixaUiYuxyDhc1nIlFzlttFOMXv1RC+3cdMN+WGZoGtrpgUW3lt
Ra/8uDM/icI2aJz0oEpw5xU6eZlLuDQWKncA/OG8mrqAs63JWtbZARigwWZ8jbYg
GgQJnB5fD6vkhBOOAgi547yo/qfSZBCS6IUTFWBIkMBeMrB0Kd6y5iGrGzNta5Yp
8fqCaE8sb7vlwd59mQzE0NfRPqupEboPhCQgvWWy++C3pfTXETnza6qbV7murPxH
G1wwdc3aBMb2EB2GddyWqQ7aOOUKYPaITAQYEQIADAUCN+pW4AUJCWYBgAAKCRAG
q29utAbt2UcPAJwJxZ82cIy4dLyuSbtrJRO7D/XeCgCZAaOuLObFRAx1V+RGpnwv
zZblDdw=
=1Lab
-----END PGP PUBLIC KEY BLOCK-----
PGP key is no longer valid. Please delete the key from your keyring if
you have it. Next delete pgp (-;