View previous topic :: View next topic |
Author |
Message |
Emperor n00b
Joined: 09 Jul 2002 Posts: 54 Location: Enschede, The Netherlands
|
Posted: Sun Sep 15, 2002 11:39 pm Post subject: gcc bug? |
|
|
hi there.
While programming i think i found a gcc bug.
try this program
Code: |
#include <math.h>
main ()
{
float x = 100.2;
short a = (short) roundf(x);
printf("%d", a);
} |
My result is 128 (and 0 for x=50.2)
What is happening: gcc loads x after rounf as float, stores it on the stack as double. lrintf is then called, which treats the stack as float.
I get exceptions as hell when a nice value of 2 is read as xx.xxE19
I am not sure if this is a header or gcc problem. I asked some other guy who has an other distro (suse 8.0). He got errors too
hmm i tried this:
Code: |
#include <math.h>
main ()
{
float x = 120.2;
int a = lrintf(x);
printf("%d %f \n", a, roundf(x));
}
|
results in -2 0.0000
btw.. gcc 2.95.3 and gcc 3.2 _________________ What is this "signature" thing you are talking about? |
|
Back to top |
|
|
Emperor n00b
Joined: 09 Jul 2002 Posts: 54 Location: Enschede, The Netherlands
|
Posted: Mon Sep 16, 2002 12:01 am Post subject: |
|
|
Hmm to specify how i found out.
Thy this Code: |
include <math.h>
main (){short a = (short) round(120.2);printf("%d\n", a);}
|
results in 8192 _________________ What is this "signature" thing you are talking about? |
|
Back to top |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Mon Sep 16, 2002 12:20 am Post subject: |
|
|
You need to compile with -D_GNU_SOURCE to make the function declarations visible from math.h. If you had compiled with a -Wall flag, you would have seen many warnings about implicitly-declared functions. |
|
Back to top |
|
|
Emperor n00b
Joined: 09 Jul 2002 Posts: 54 Location: Enschede, The Netherlands
|
Posted: Mon Sep 16, 2002 1:51 pm Post subject: |
|
|
Thank you _________________ What is this "signature" thing you are talking about? |
|
Back to top |
|
|
|