Enhancement request: support floating point variables in FOR
marianodominguez opened this issue · 2 comments
marianodominguez commented
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!
marianodominguez commented
That makes sense.
still wrapping my head on mixing integer and float variables.
thanks !
…On Thu, Apr 6, 2023 at 6:41 AM dmsc ***@***.***> wrote:
Hi!
Sorry, I won't implement this, as FOR loops with floating point variables
are a bad idea:
- It is s 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!
—
Reply to this email directly, view it on GitHub
<#71 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOXJI6N7CYP24ULJ7KFK53W73BYFANCNFSM6AAAAAAWU53E4Y>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
_______________________________
Mariano Domínguez Molina
_______________________________