Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
gcc bug?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Emperor
n00b
n00b


Joined: 09 Jul 2002
Posts: 54
Location: Enschede, The Netherlands

PostPosted: Sun Sep 15, 2002 11:39 pm    Post subject: gcc bug? Reply with quote

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
View user's profile Send private message
Emperor
n00b
n00b


Joined: 09 Jul 2002
Posts: 54
Location: Enschede, The Netherlands

PostPosted: Mon Sep 16, 2002 12:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Mon Sep 16, 2002 12:20 am    Post subject: Reply with quote

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
View user's profile Send private message
Emperor
n00b
n00b


Joined: 09 Jul 2002
Posts: 54
Location: Enschede, The Netherlands

PostPosted: Mon Sep 16, 2002 1:51 pm    Post subject: Reply with quote

Thank you :)
_________________
What is this "signature" thing you are talking about?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum