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

Having trouble with Signed and Unsigned INT type conversions

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



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Having trouble with Signed and Unsigned INT type conversions
PostPosted: Tue Oct 28, 2003 2:01 pm     Reply with quote

This is what I have that works correct.

Int Nset;
Float Nor_f

Nset = 10;
Nor_f = Nset/.0001174;

Nor_f now = 85178.875

This is all fine and what I expected!

But I need to change Nset to a sign int so that if I decrement Nset I can test for <= zero.

Signed Int Nset;
Float Nor_f

Nset = 10;
Nor_f = Nset/.0001174;

Nor_f now = 5.1265171797906E-32

There must be some thing about type conversions / promotions that I don’t understand.
If I type cast Nset in to a float then it works just fine.
But I though with the constant being a float that the complier would promote Nset to a float automatically?


Signed Int Nset;
Float Nor_f

Nset = 10;
Nor_f = (float)Nset/.0001174;

Nor_f now = 85178.875

Can someone give me insight me on this?

Thank All
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 28, 2003 4:14 pm     Reply with quote

The rule with CCS is, if it doesn't work, then type cast it.

(ie., Do whatever you have to do, to make it work).
Birdie
Guest







PostPosted: Wed Nov 12, 2003 5:41 pm     Reply with quote

I agree with PCM Programmer whole-heartedly!
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