algorithmic modeling for Rhino
Tags:
Thanks a lot David!
When I placed 0.5 as Step my GH crashed...
Is it not possible to have decimal increments?
Greetings,
Arthur
Not when your iteration variable is an integer.
It is generally a bad idea to use decimal increments in loops, as it might lead to significant binary noise in the logic.
Let's for the sake of argument assume that the number 0.5 cannot be exactly represented using a 64-bit floating point number. So what's actually stored in the memory is something like 0.4999999997 or 0.500000000002
Now, when you run a loop and you add this increment to a starting value, say 100 times, then you amplify that discrepancy with about a hundred. Eventually, when you were supposed to hit the 50.0 mark, you're only at 49.99999997, which is less than 50.0, which means you'll get an extra iteration.
When you use floating point iteration counters, you'll also need to be smart and adjust your loop limit accordingly. I find it much easier to use integers in loops (integer math is always exact) and then compute a floating point value inside the loop from the integer. This avoids both cumulative floating point rounding and the aforementioned extra iteration problem.
And I don't think Grasshopper crashed. It just got stuck in an infinite loop, as 0.5 has its decimal portion stripped, which means you were adding 0 to i every iteration which meant you weren't getting anywhere.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by