CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to convert float to long?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tomasch



Joined: 14 May 2004
Posts: 3

View user's profile Send private message

How to convert float to long?
PostPosted: Wed May 19, 2004 9:26 pm     Reply with quote

I have a 7 segment LED display routine that requires a long (16bits) data type.

I have to do some fancy calculations that require float. I know how to cast up to float but how do you "cast down"

I have tried the following...

float x=12.34
long y

both y=x and y=(long) x give y a value of 0 (zero)

Any ideas?

Thanks in Advance

Tom
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu May 20, 2004 7:21 am     Reply with quote

What are you expecting "y" to be in your example?

An assignment operation should make y=12 (truncation). If it is coming back as zero there may be a compiler bug so I'll ask the 64 cent question, what version of compiler are you using?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Thu May 20, 2004 8:03 am     Reply with quote

I'm expecting y=12 and it's 0

Version is CCS v 3.112 (I think! - How do I verify)
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu May 20, 2004 8:12 am     Reply with quote

Select 'Help' on the menu bar and then 'About'. This will tell you which version you have.
Guest








PostPosted: Thu May 20, 2004 9:33 am     Reply with quote

Using the PCM version - in looking at some of the files in the directory - it's 3.112
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu May 20, 2004 7:03 pm     Reply with quote

You probably don't want to hear this but I think it is a compiler bug.

Try being a little more specific with your variable declarations:

Code:

float x=12.34;
signed long int y; // or "unsigned" instead of "signed", just be consistant with the cast later

y = (signed long int)x;


See if that helps.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group