math
math
i was looking at the math results in the debugger for a pow(50,3). the results should be 12,500 but they are 59xxx. the lcd shows the same value. where can i see the actual value. or is it a binary value that as to be converted to decimal to display the correct value.
Re: math
If you are storing the result into a word variable, then it will be 59464.
You have to store it into something larger than word, longword would be enough:
You have to store it into something larger than word, longword would be enough:
Code: Select all
dim ggg as longword
main:
...
ggg = pow(50, 3)
...
end.
Hi,
What version of compiler you use ?
I use 5.0 and at me, in simulator, everything it's OK.
result is 1.250000E+005
What version of compiler you use ?
I use 5.0 and at me, in simulator, everything it's OK.
Code: Select all
program Test_Pow
dim res as float
main:
res = pow(50.0,3.0)
nop
end.
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
tried the dim ggg as longword
w0 comes out as 59463
same as the word
it also shows up on the lcd as 59463
tried the dim ggg as float
it comes up with a odd number but no 125000
the comipler is 5.0
just want to be able to do math with these chips
the number on ggg as real,float is 1207182332
ok ggg comes 124999
canged the wordtostr to longwordtostr and everything comes to the lcd correctly.
w0 comes out as 59463
same as the word
it also shows up on the lcd as 59463
tried the dim ggg as float
it comes up with a odd number but no 125000
the comipler is 5.0
just want to be able to do math with these chips
the number on ggg as real,float is 1207182332
ok ggg comes 124999
canged the wordtostr to longwordtostr and everything comes to the lcd correctly.
hey thanks for your help. as you can i'm not to familiar with mb programming.
my job keeps me away from this stuff.
however i would like to make a mobile robot that follows poeple around, but i havnt been able to find a thermal sensor array 15x15. to follow someone's heat signature. hard to find sensor.
my job keeps me away from this stuff.
however i would like to make a mobile robot that follows poeple around, but i havnt been able to find a thermal sensor array 15x15. to follow someone's heat signature. hard to find sensor.
-
- Posts: 1
- Joined: 15 Sep 2008 12:31
Math question
Hi rverm,
I have ever math problems. I'm begginer programmer for dspic, but I can't understand some cases that happening to me.
For example, I need to store a Coeficient in EEPROM. There is 'Coef' variable as float. My Coef is ever greater than 0 and under '1'.
So, to write this value to eeprom first I convert to Longint multiplying for 100000000, to use all precision os Coef. Then I write using Loword and HiWord commands.
After writted I need to reload this varible, reading word by word, then multiplying for 0.00000001
I appreciate all idea to simplify this rotine, because there is to slow and
need many variables only to do it.
Thanks!
I have ever math problems. I'm begginer programmer for dspic, but I can't understand some cases that happening to me.
For example, I need to store a Coeficient in EEPROM. There is 'Coef' variable as float. My Coef is ever greater than 0 and under '1'.
So, to write this value to eeprom first I convert to Longint multiplying for 100000000, to use all precision os Coef. Then I write using Loword and HiWord commands.
After writted I need to reload this varible, reading word by word, then multiplying for 0.00000001
I appreciate all idea to simplify this rotine, because there is to slow and
need many variables only to do it.
Thanks!
Re: Math question
Try this:
This example shows how to extract bytes from a float variable by using pointers. It can be easily modified to write the float variable to eeprom.
Code: Select all
program test
dim Ptr as ^byte
dim FloVar as float
main:
FloVar = 1.2345 ' = 0x3F9E 0419
Ptr = @flovar
latb = Ptr^ ' latb = 0x19
Ptr = Ptr + 1
latb = Ptr^ ' latb = 0x04
Ptr = Ptr + 1
latb = Ptr^ ' latb = 0x9E
Ptr = Ptr + 1
latb = Ptr^ ' latb = 0x3F
Ptr = Ptr + 1
end.