POV-Ray : Newsgroups : povray.general : Problems with iterations : Re: Problems with iterations Server Time
31 Jul 2024 02:27:12 EDT (-0400)
  Re: Problems with iterations  
From: SharkD
Date: 10 Jan 2008 16:05:00
Message: <web.478687b0f1dc5f73d410b38f0@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'm wondering if simply changing the condition to "i < 0.999999" is sufficient.
The likelihood of the variable falling outside this range is pretty slim. Also,
to how many decimal places does POV-Ray calculate? I thought the "system
specific" option in the "str" function returned values using this amount.


Post a reply to this message

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