Floating Point Routines
brs
Posts: 33
I'm having difficulty using the Sin and Cos functions included in the Float32Full.spin file obtained from the objects library. It appears negative values are not being computed correctly. For example, the following two computations:
tmp := f.Sin(f.FDiv(PI,4.0))
tmp := f.Sin(f.FDiv(-PI,4.0))
should result in 0.70710678 and -0.70710678, respectively. However, my propeller is outputting 0.70710678 for both.
Float32Full.spin is coded in assembly to which I have little experience in. Any suggestions?
Regards,
B
tmp := f.Sin(f.FDiv(PI,4.0))
tmp := f.Sin(f.FDiv(-PI,4.0))
should result in 0.70710678 and -0.70710678, respectively. However, my propeller is outputting 0.70710678 for both.
Float32Full.spin is coded in assembly to which I have little experience in. Any suggestions?
Regards,
B
Comments
Runtime expressions are always treated as integer. So, that -PI is getting two's-complemented as a binary number - this is not what you need. You need to use CONSTANT(-PI) to have this properly computed (at compile time). I may need to modify the compiler to prohibit any integer operations on floating point constants to get people around this pitfall. I'll be thinking about what to do in these cases that makes the most sense. Sorry for the trouble.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
B
tmp := f.Sin(f.FDiv(PI,4.0))
tmp := f.Sin(f.FDiv(-PI,4.0))
tmp := f.Sin(f.FDiv(PI,4.0))
tmp := f.Sin(f.FDiv(constant(-PI),4.0))
tmp := f.Sin(0.7854)
tmp := f.Sin(-0.7854)
I'm using the parallax four line serial lcd and debug_lcd.spin object as my debugger. Any suggestions?
Regards,
B
Post Edited (brs) : 6/13/2006 3:41:44 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
Chip Gracey
Parallax, Inc.
Cam Thompson
The code for Sin/Cos in Float32Full was slightly out of sync with the correct code in Float32. The testing was done using Float32, so the problem in Float32Full slipped by. They are now in sync, and I've included a new set of routines (the only change is Float32Full). The most up-to-date version of Float32Full is now V1.1 - June 22, 2006.
Cam Thompson
Micromega Corporation