Represent 22.34564 in the Stamp memory as 22346. Then 22346 / 5 = 4469, which represents 0.04469.
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.
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.
After reading your Application Notes on your website, I thought I would take a step back and try to simplify it the math processing. I went ahead and purchased a uMFPU from Parallax. Hopefully, this will be somewhat easy to operate
Yes, the uFPU will let you focus on your problem at hand instead of the math details. A lot depends on what you want to do. If it is a scaling problem that can fit within the 16 bit precision, there is probably a relatively simple way to do it with the ** or */ operator or a calculation loop if the variable is in the denominator. But if you really need precision like 22.34564, or if you floating point math functions without so much concern about scaling and overflow, then the uFPU is certainly the way to go.
If your needs are simple such as always dividing by a decimal constant, the Stamp help on */ says you can use hex like $01A3. Since I didn't exactly know how to convert or what number I needed, I just ran the program a few times in Stamp debugger changing the values until I got results in the range I wanted.
Of course if you need to change the decimal variable frequently then you're on the right track.
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".
I have tried using the uMFPU and I can add to floats together by using the following code:
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
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.
Thanks bruce. I actually found out that it was because I was sending a single Byte, and not the entire byte array. I should needed to update the code to shiftout each byte within the array:
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.