|
|
Nicolas Alvarez wrote in message <4903699f@news.povray.org>:
> It's mainly relevant if you loop thousands of times. With 100 iterations
> it's not a big problem :)
Quite the contrary, with this code, there may be problems even for a very
small number of iterations.
For example, consider the following code:
#local n = 10;
#local t = 0;
#while(t < 1)
#local t = t + 1/n;
#end
and the same with n = 11. It happens that the float value for 1/10 is
slightly smaller than the exact value 1/10, while the float value for 1/11
is slightly greater than the exact value for 1/11. The result is that both
loops make 11 iterations.
This issue can be fixed by using a float-friendly bound, as suggested
earlier by someone: t < 1 + dt / 2 or t < 1 - dt / 2, depending on whether
the loop is supposed to be inclusive or not.
Post a reply to this message
|
|