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 04:00:00
Message: <web.4785ddf4f1dc5f73f6ab856c0@news.povray.org>
"Fredrik Eriksson" <noo### [at] nowherecom> wrote:
> On Thu, 10 Jan 2008 08:22:20 +0100, SharkD <nomail@nomail> wrote:
> > "SharkD" <nomail@nomail> wrote:
> >> Check out this test scene:
> >>
> >> #local i = 0;
> >> #local numerator = 1;
> >> #local divisor = 6;
> >> #while(i < numerator)
> >>  #local i = i + numerator/divisor;
> >>  #debug concat("i = ", str(i, 0, -1),"\n")
> >> #end
> >>
> >> Shouldn't the iterations stop when i = 1? What am I doing wrong?
> >
> > Just to be clear, the last entry printed to the Messages panel is "i =
>
> > 1.166667".
>
>
> You should move the variable update (i.e. "#local i = i +...") to the
> end
>
> of the loop. You should also realize that comparing floating point numbe
> rs
>
> like this is problematic at best, and should generally be avoided.
>
>
>
> --
>
> FE

I moved the incrementor to the end of the loop as you suggested:

#local i = 0;
#local numerator = 1;
#local divisor = 6;
#while(i < numerator)
 #debug concat("i = ", str(i, 0, -1),"\n")
 #local i = i + numerator/divisor;
#end

The result, however, lists seven iterations:

i = 0.000000
i = 0.166667
i = 0.333333
i = 0.500000
i = 0.666667
i = 0.833333
i = 1.000000

There should only be six!


Post a reply to this message

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