BS2P Math Operations
spaine
Posts: 51
I am trying to perform a math operation such as: 22.34564 / 500, but I'm not sure how this would be done.
Any ideas?
Thanks!
Any ideas?
Thanks!
Comments
That is a quick view, and it is hard to say more without knowing specifics of what you are trying to accomplish. The Stamp only does 16 bit integer math, and to get precise results you have to draw from an arsenal of ad hoc tricks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for the help. I see what you mean about the 16 bit math. I was just reading your AppNote at EME Systems. Do you mind if I contact you about this topic, if I have further questions?
I'm actually kind of lost by your AppNote. That is, I don't think I personally have enough knowledge of the topic to understand it.
Thanks,
Stephen
Thanks for the help Tracy.
Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Of course if you need to change the decimal variable frequently then you're on the right track.
Kirk
A uFPU is a small, math co-processor which is capable of (F)loating (P)oint calculations, among other things. Thus uFPU is "micro Floating Point Unit".
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
http://www.parallax.com/detail.asp?product_id=604-00030
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Main:
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]SELECTA+1, ATOF, "123.123", 0, FSET]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]ATOF, "100.100", 0, FADD]
GOSUB Print_Float
END
I get the correct "223.223" result, however I get something like "1.4085" when I try to use the below code. That is, I take input from either an end-user or from a device such as a GPS.
NUM1 VAR Byte (7)
NUM2 VAR Byte (7)
Main:
DEBUG CR, "Please enter the first number to be added: "
DEBUGIN Str NUM1\6
DEBUG CR, "Please enter the second number to be added: "
DEBUGIN Str NUM2\6
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]SELECTA+1, ATOF, NUM1, 0, FSET]
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]ATOF, NUM2, 0, FADD]
GOSUB Print_Float
END
If I provide "123.123" for NUM1 and "100.100" for NUM2, I get the result of "1.4085" for the above code.
Am I using Byte wrong?
Again help is greatly welcomed. I have to admit, I know very little about the uMFPU.
This may not be the whole problem, but how is SHIFTOUT supposed to know whether is should send out 1, 2, 3, 4, 5, or 6 bytes of data for NUM1 and NUM2? Perhpas a length specification would be appropriate?
I know just about nothing about uFPU's but are you suppposed to be string or numeric data to it? Just something to consider.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]SELECTA+1, ATOF, NUM1(0), NUM1(1),..., NUM1(6), 0,
FSET, ATOF, NUM2(0), NUM2(1),..., NUM2(6), 0, FADD]
Again, thanks for the help. I'm having fun, but I have to admit there is something new to discover each day.