Page 1 of 1
BUG ?
Posted: Sat Nov 27, 2010 10:30 am
by PEB
Code: Select all
Function p_Steps()
StepVar=StepVar+0.1
If StepVar=1.1
DebugPrint("Yep 1")
ElseIf StepVar=1.2
DebugPrint("Yep 2")
ElseIf StepVar=1.3
DebugPrint("Yep 3")
EndIf
If StepVar=1.3
DebugPrint("Done")
End()
EndIf
DebugPrint(StepVar)
EndFunction
StepVar=1
Function p_Test()
SetInterval(1, p_Steps, 100)
EndFunction
InstallEventHandler({OnMouseUp=p_Test})
Repeat
WaitEvent
Forever
StepVar=1.1 is recognized, but 1.2 and 1.3 are not.
Any ideas?
Re: BUG ?
Posted: Sat Nov 27, 2010 9:54 pm
by airsoftsoftwair
Welcome to the wonderful world of floating point arithmetic
It's not a Hollywood bug... see Wikipedia for more info:
http://en.wikipedia.org/wiki/Floating_p ... y_problems
A simple workaround would be to use
Round() on the floating point value. Then it should work.
Re: BUG ?
Posted: Sun Nov 28, 2010 12:36 am
by PEB
Thanks for the explanation!
I don't really need to use a decimal here. And even if I choose to use a variable with a decimal (as in the example), it's really not hard to work around this issue by multiplying by 10 before the variable comparison and then dividing by 10 afterwards. I just thought the observed behavior was odd, and that this might have been a bug of some sort.