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

PIC & floating point numbers

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



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

PIC & floating point numbers
PostPosted: Tue Aug 02, 2005 7:30 am     Reply with quote

Hello all,

I am having an issue with floating point numbers. If I define 4 floats,
float q1, q2, q3, q4;

and after some calculations they have values of:
q1 = 0.9224;
q2 = 0.345;
q3 = 0.0024;
q4 = 0.05;

the PIC I am using (16F84) will view q1, q2, q3, q4 as zero. This I figured because I didn't think it was able to work with floating point numbers. However, I thought that if I did something like q1*10, q1 would take an integer value of 9 and it would not be like multiplying 0*10 which would give me zero. But, that's what I seem to be getting. Does anyone know why?

Also, are there any PICs that can work with floating point numbers directly?

Thanks in advance,
weg
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Aug 02, 2005 8:30 am     Reply with quote

Try this

q1*10.0

It should fix you type casting problem.
Guest








PostPosted: Tue Aug 02, 2005 8:32 am     Reply with quote

Hi,
just post the code where you have your calculations, a bad casting of variables in floating point maths could resuls in a variable value of 0.

i.e. if you multiply q1 with an integer variable without explicitely casting this integer to float, you will have a result being an integer and not a float... and 0.xxx in integer format IS 0

int myInt=2;
float myFloat=0.213;

myFloat=myFloat*myInt will be 0

myFloat=myFloat*(float)(myInt) will be 0.426
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