|
![](/i/fill.gif) |
Warp <war### [at] tag povray org> wrote:
> SharkD <nomail@nomail> wrote:
> > There should only be six!
>
> You have found the inaccuracies of floating point numbers.
>
> If you want an exact number of iterations, use integers, and at the
> beginning of the loop, calculate the actual value you want to use from
> that integer loop counter.
>
> For example, assume you want a loop with a variable which goes from
> 0 to 1 at steps of 0.1, and stops before it reaches the 1. The correct
> way to do that is:
>
> #declare Index = 0;
> #while(Index < 10)
> #declare Value = Index/10;
>
> ... (the body of the loop here, which uses 'Value') ...
>
> #declare Index = Index+1;
> #end
>
> This would be the *wrong* way of doing it:
>
> #declare Value = 0;
> #while(Value < 1)
> ...
> #declare Value = Value + 0.1;
> #end
>
> --
> - Warp
I changed my code to the following, but still receive the same erros.
#local radii = 6;
#local increment = 1/radii;
#local i = 0;
#local max = radii * increment;
#while(i < max)
#local i = i + increment;
#debug concat("i = ", str(i, 0, -1),"\n")
#end
If "increment" is indeed stored as a float, shouldn't "6 * increment" evaluate
to the same number as "increment + increment + increment + increment +
increment + increment"?
Post a reply to this message
|
![](/i/fill.gif) |