Newbie Programming Questions
robotics
Posts: 90
Hi,
<i hope this didn't get posted multiple times as I had to press the "submit" button multiple times>
A have a couple super basic Spin programming questions, regarding the following code (below):
I noted that when reading from the DAT area either numeric constants (pi) or square roots of constants (^^2), or the products of two constants (2.0 * 3.0). the correct resultant numbers (3.1416, 1.1412, 6) are displayed in Examples 1,2,3. I also noted that in Example 4 that when the numeric floating point constant "9.0" is used as an argument in the display command, that it also displays properly as "9".
Two questions:
1) Why is it that in Example 5 when the variable "Temper" is used to store the product of "9.0 * 3.0", and then this variable is used as the argument for the display function that the number "0" is displayed instead of "27"?
2) In Example 6, why does the argument "9.0 * 3.0" yield "0" whereas when two operands and a multiplication operator are retrieved from the DAT area and used in the display argument that the correct result is displayed?
In advance, many thanks for your assistance!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
term : "tv_terminal"
fp : "FloatString"
PUB start | i, Temp , Temper
'start the tv terminal
term.start(12)
'change color
term.out(3)
fp.SetPrecision(5)
' EXAMPLE 1 Displays "3.1416"
Temp := fnums1[noparse][[/noparse]0]
term.str(fp.FloatToString(Temp))
term.out(13)
' EXAMPLE 2 Displays "1.4142"
Temp := fnums1
term.str(fp.FloatToString(Temp))
term.out(13)
' EXAMPLE 3 Displays "6"
Temp := fnums1
term.str(fp.FloatToString(Temp))
term.out(13)
term.out(13)
' EXAMPLE 4 Displays "9"
term.str(fp.FloatToString(9.0))
term.out(13)
' EXAMPLE 5 Displays "0" ????????
Temper := 9.0 * 3.0
term.str(fp.FloatToString(Temper))
term.out(13)
' EXAMPLE 6 Displays "0" ?????????
term.str(fp.FloatToString(9.0 * 3.0))
term.out(13)
DAT
fnums1 long pi, ^^2.0, 2.0 * 3.0, 3.0 * 7.0, 1.0 / ^^2.0, -0.0000000000194, 1.0 / 13.0, 0
<i hope this didn't get posted multiple times as I had to press the "submit" button multiple times>
A have a couple super basic Spin programming questions, regarding the following code (below):
I noted that when reading from the DAT area either numeric constants (pi) or square roots of constants (^^2), or the products of two constants (2.0 * 3.0). the correct resultant numbers (3.1416, 1.1412, 6) are displayed in Examples 1,2,3. I also noted that in Example 4 that when the numeric floating point constant "9.0" is used as an argument in the display command, that it also displays properly as "9".
Two questions:
1) Why is it that in Example 5 when the variable "Temper" is used to store the product of "9.0 * 3.0", and then this variable is used as the argument for the display function that the number "0" is displayed instead of "27"?
2) In Example 6, why does the argument "9.0 * 3.0" yield "0" whereas when two operands and a multiplication operator are retrieved from the DAT area and used in the display argument that the correct result is displayed?
In advance, many thanks for your assistance!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
term : "tv_terminal"
fp : "FloatString"
PUB start | i, Temp , Temper
'start the tv terminal
term.start(12)
'change color
term.out(3)
fp.SetPrecision(5)
' EXAMPLE 1 Displays "3.1416"
Temp := fnums1[noparse][[/noparse]0]
term.str(fp.FloatToString(Temp))
term.out(13)
' EXAMPLE 2 Displays "1.4142"
Temp := fnums1
term.str(fp.FloatToString(Temp))
term.out(13)
' EXAMPLE 3 Displays "6"
Temp := fnums1
term.str(fp.FloatToString(Temp))
term.out(13)
term.out(13)
' EXAMPLE 4 Displays "9"
term.str(fp.FloatToString(9.0))
term.out(13)
' EXAMPLE 5 Displays "0" ????????
Temper := 9.0 * 3.0
term.str(fp.FloatToString(Temper))
term.out(13)
' EXAMPLE 6 Displays "0" ?????????
term.str(fp.FloatToString(9.0 * 3.0))
term.out(13)
DAT
fnums1 long pi, ^^2.0, 2.0 * 3.0, 3.0 * 7.0, 1.0 / ^^2.0, -0.0000000000194, 1.0 / 13.0, 0
Comments
Thank you for your explanation. Just one follow-up question. Why did the floating point constant expression "2.0 * 3.0" in the DAT section get properly evaluated at run time whereby the displayed result was "6"?
Again my thanks as I was now able to write a program using a floating point object!
I hope I don't sound like that old tv show Columbo, but if you don't mind, if I could ask one last question.
I commented out the float object and ran the program and noted that as you said the "2.0 * 3.0" was performed at compile time. But, if the propeller doesn't perform float operations without a float object, how did the propeller compile the float expression of "2.0 * 3.0" ?
In advance, thank you.
It's not the propeller doing the compilation. It's all done on your PC (running the Propeller Tool or bst[noparse][[/noparse]c]). SPIN and PASM have to be compiled/assembled into a propeller binary which is then subsequently uploaded to the propeller chip.