POV-Ray : Newsgroups : povray.general : Problems with iterations : Re: Problems with iterations Server Time
31 Jul 2024 02:29:20 EDT (-0400)
  Re: Problems with iterations  
From: Warp
Date: 10 Jan 2008 06:33:25
Message: <47860285@news.povray.org>
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


Post a reply to this message

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