Shop OBEX P1 Docs P2 Docs Learn Events
Back to basic Floating poit math...UGH! — Parallax Forums

Back to basic Floating poit math...UGH!

Sniper KingSniper King Posts: 221
edited 2008-05-30 19:59 in Propeller 1
OK, I think I'm dumb!· I can't figure out how to use the FloatMath Object.· I understand the use of the different methods, that is no problem.· this example is extreme but basic.· X and Y need to be used other places.· I need to have X and Y be float values so as to use them elsewhere!!!!· The Single declaration is a joke...sort of!



OBJ
·····
··· Fp· : "FloatMath"
··· FS· : "FloatString"

VAR

······Long X
······Long ·Y
····· Single Z···· '··· LOL

Pub· Whatever | z

X:=56.2
Y=25.5
Z=fp.Fmul(x,y)



Pub Answer


' Show 'z' in whatever fashion






▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Was it pin 11 or 26?· Hmmm....··I think the smell of smoke tells the whole story.· Must be 26.



Michael King
Application Engineer
R&D
Digital Technology Group

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-30 19:56
    All variables are either bytes, 16-bit words or 32-bit long words or arrays of them. Floating point values are stored in 32-bit long words and the Spin compiler does not know what you're storing there and assumes it's an integer. You'd declare "Z" as a LONG just like "X" or "Y". You can assign floating point constants to a long because the compiler does know about floating point constants and converts them to 32-bit long values. Do remember that the assignment operator is ":=". "Y := 25.5" should work as should "Z := fp.FMul(x,y)". As far as the compiler is concerned, the result of "fp.FMul" is a 32-bit long value. As long as you pass that value to routines that assume the value is a floating point number, you'll be fine.
  • Sniper KingSniper King Posts: 221
    edited 2008-05-30 19:59
    My hero!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Was it pin 11 or 26?· Hmmm....··I think the smell of smoke tells the whole story.· Must be 26.



    Michael King
    Application Engineer
    R&D
    Digital Technology Group
Sign In or Register to comment.