POV-Ray : Newsgroups : povray.general : Array Question : Re: Array Question Server Time
9 Aug 2024 17:23:00 EDT (-0400)
  Re: Array Question  
From: Mike Williams
Date: 2 Jun 2000 16:48:43
Message: <4z$1BGAC1BO5EwZ6@econym.demon.co.uk>
Wasn't it Chris S. who wrote:
>error:  no matching } in sphere_sweep, < found instead
>
>/////
>
>#declare Rand01 = seed(34747);
>#macro Tree_Root(X,Y,Z,R,L,Next)
>    #declare counter=0;
>    sphere_sweep {
>      linear_sphere_sweep,
>      10,
>      #while(Next>0)
>        <X,Y,Z>,R
>        #declare R=R/1.05;
>        #local X=X-rand(Rand01)*2;
>        #local Y=Y-rand(Rand01);
>        #local Z=Z-rand(Rand01)*2;
>        #declare Next=Next-.1;
>        #declare counter=counter+1;
>     #end
>    }
>#end
>union{
>Tree_Root(0,0,0,2,1,1)
>pigment{color rgb <1,0,0>}}
>
>//////

It's a rounding error.

If you subtract .1 from 1 10 times you get a number that's not quite
exactly zero, because floating point arithmetic is never exact. So,
after the tenth iteration "Next" turns out to be very slightly greater
than zero, so "#while(Next>0)" is still true, and the eleventh iteration
produces the error.

Dirty fix:   #while(Next>0.01)

Clean fix: #while(counter<10)

This is a better fix because it will work even if you call the Tree_Root
macro with the sixth parameter not equal to 1.


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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