Shop OBEX P1 Docs P2 Docs Learn Events
Problem with FloatMath — Parallax Forums

Problem with FloatMath

VGVG Posts: 32
edited 2009-01-23 05:56 in Propeller 1
Hi All,
·· I am having this weird problem:


VAR
·· long· Temp, Temp2, SpeedB, SpeedA

OBJ
··· FA : "FloatMath"

PUB x
.......
SpeedB = 100
SpeedA := Fa.FMul(SpeedB,Fa.FDiv(Temp2,Temp))
.......

When·Temp2 > Temp SpeedA has·correct values, around 100.
When Temp2 < Temp SpeedA is having values close to 10,000. It seems the value is multiplied by 10. Why and How???· I did not change FloatMath.

Sincerely,
VG

Comments

  • mirrormirror Posts: 322
    edited 2009-01-23 05:56
    This one comes up quite often, and has 2 solutions:

    1) SpeedB := 100.0 'Make SpeedB a compile time floating point value.

    -or-

    2) Do integer to float conversion at run time:
    SpeedA := Fa.FMul(Fa.FFloat(SpeedB),Fa.FDiv(Temp2,Temp))

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.