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

cast "signed int" to "float"? Doesn't wo

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







cast "signed int" to "float"? Doesn't wo
PostPosted: Wed Nov 10, 2004 8:07 am     Reply with quote

I tried the following:

Suppose i have the following float and signed int:
signed int x;
float y;
float z;

....

z = y + (float) x;

That's not going to give me desired values, right?

e.g.
y = 10.0
x = -4

z will not evaluate to something like 6.0 (or 5.99999), right?
valemike
Guest







PostPosted: Wed Nov 10, 2004 8:32 am     Reply with quote

I also found that:

unsigned int x;
float y;
float z;

If i then write the following:

z = y + (float) x;
It doesn't work right!

I have to break it up into two steps:
z = (float) x;
z = z + y;

Has anyone noticed that?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Nov 10, 2004 10:45 am     Reply with quote

What answer does it give you?

Also what complier version are you using?

I am using 3.104 with 16C771 chips. I do lots of casting and it all works fine. But I don't use floats.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







Re: cast "signed int" to "float"? Doesn'
PostPosted: Wed Nov 10, 2004 10:55 am     Reply with quote

valemike wrote:
I tried the following:

Suppose i have the following float and signed int:
signed int x;
float y;
float z;

....

z = y + (float) x;

That's not going to give me desired values, right?

e.g.
y = 10.0
x = -4

z will not evaluate to something like 6.0 (or 5.99999), right?

Wat you post should work, and has worked OK for me in the past. However I'd probably bracket the cast to seperate it from the arithmetic.
So:
z=y+((float)x);

I have seen problems in the past, with the arithmetic, seeming to get confused by the cast, unless the extra brackets are added.
What are you seeing?.

Best Wishes
valemike
Guest







PostPosted: Wed Nov 10, 2004 11:15 am     Reply with quote

I wish I could pull this whole topic thread Rolling Eyes

I realized that i forgot to read the result from eeprom after a hard reset. False alarm! Sorry.

I couldn't verify the result myself because the unit i'm working uses rb6 and rb7, nor does it have a MAX232 with which to connect to Hyperterminal.
Ttelmah
Guest







PostPosted: Wed Nov 10, 2004 11:23 am     Reply with quote

valemike wrote:
I wish I could pull this whole topic thread Rolling Eyes

I realized that i forgot to read the result from eeprom after a hard reset. False alarm! Sorry.

I couldn't verify the result myself because the unit i'm working uses rb6 and rb7, nor does it have a MAX232 with which to connect to Hyperterminal.

It happens.
Why though did you think that seperating the lines was making it work, if you couldn't really test it?.
You can allways output a 'diagnostic' byte at a low baud rate, on any pinm and latch this on a digital scope, or simply flash an LED really slowly, and count the pulses, if you have even one pin available.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Wed Nov 10, 2004 11:39 am     Reply with quote

Well if you are using MPLAB, there is a simulator in there that works just great for these tests. That is how I would have tested it.
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