|
|
View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
PIC & floating point numbers |
Posted: Tue Aug 02, 2005 7:30 am |
|
|
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
|
|
Posted: Tue Aug 02, 2005 8:30 am |
|
|
Try this
q1*10.0
It should fix you type casting problem. |
|
|
Guest
|
|
Posted: Tue Aug 02, 2005 8:32 am |
|
|
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 |
|
|
|
|
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
|