dmsc/fastbasic

Enhancement request: support floating point variables in FOR

marianodominguez opened this issue · 2 comments

things like

for th%=-PI% to 2*PI% step PI%/20

should be possible to implement, this will avoid while / loop refactors

maybe another imp if the loop variable is float.

dmsc commented

Hi!

Sorry, I won't implement this, as FOR loops with floating point variables are a bad idea:

  • It is a lot slower, as you have an extra floating-point comparison on each step.
  • Is nor predictable, as floating-point math is not exact. In your example above you will loop 59, 60 or 61 times depending on the floating-point implementation and rounding.

Correct way to implement above loop is:

th%=-PI%
FOR i=0 TO 60
   '..... do something...
   th% = th% + PI%/20
NEXT

Have Fun!