POV-Ray : Newsgroups : povray.general : Problems with iterations : Re: Problems with iterations Server Time
31 Jul 2024 08:31:05 EDT (-0400)
  Re: Problems with iterations  
From: SharkD
Date: 10 Jan 2008 16:20:01
Message: <web.47868ae1f1dc5f73d410b38f0@news.povray.org>
Warp <war### [at] tagpovrayorg> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.