Error in Float32.spin
John Abshier
Posts: 1,116
I cannot get the Degrees and Radians functions to work.· In the code below they print as zero instead of 45 and 0.785.
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
c = 180.0 / pi
d = pi / 180.0
VAR
OBJ
Tv : "TV_Text"
F : "Float32Full"
FTS : "FloatString"
PUB Main | x, y, a, b
Tv.start(12) ' should check fail
F.start
Tv.out($00) ' clear
Tv.out($01) ' home
TV.str(FTS.FloatToString(F.Degrees(0.785))) ' prints 0 not 45
Tv.out($09)
Tv.str(FTS.FloatToString(F.Radians(45.0))) ' prints 0 not 0.785
Tv.out($09)
Tv.str(FTS.FloatToString(F.FMul(c, 0.785))) ' prints 44.97719
Tv.out($09)
Tv.str(FTS.FloatToString(F.FMul(d, 45.0))) ' prints 0.785398

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
nice to see an answer no matter where it is poster.
For those interested, this bug was a trap that I'd documented in the Tips and Traps on page 10 of the floating point document - which I then proceeded to fall into myself!
Spin recognizes floating point constants, but all expressions are evaluated as integer expressions unless you use the constant directive.
c := pi / 180.0 ' is incorrect
c := constant(pi / 180.0) ' yields the correct result
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cam Thompson
Micromega Corporation