|
|
This looks like a "feature" of many programming languages that use
floating point numbers, including POVRay's. It's caused by inaccuracies
in the floating point calculations, such that tests like "T = 1.0" or "T
< 1.0" produce weird results. Try using a test such "abs(T - 1.0) <
0.01" where 0.01 is a sufficiently small number for the accuracy you
require, and things should work okay.
Andrew
--
Ob disclaimer: Of course, I might be wrong...
Guy Rauscher wrote:
>
> Hi!
>
> This bug exsited in the 3.0 version as well but I just found out about
> it now. In certain cases (maybe its related to the use of numbers with a
> decimal point) a while loop such as this: #while(I<1) loops one time too
> many (as if it was #while(I<=1)). Just run the attached script.
>
> Guy
>
> ------------------------------------------------------------------------
[most of example snipped]
> // Doesn't work!
> #declare T = 0;
> #declare Tinterval = 0.1;
> #while(T < 1)
> #declare T = T + Tinterval;
> #debug concat("T",str(T,1,1)," ")
> #end
Post a reply to this message
|
|
|
|
Andrew Hedges wrote:
>
> This looks like a "feature" of many programming languages that use
> floating point numbers, including POVRay's. It's caused by inaccuracies
> in the floating point calculations, such that tests like "T = 1.0" or "T
> < 1.0" produce weird results. Try using a test such "abs(T - 1.0) <
> 0.01" where 0.01 is a sufficiently small number for the accuracy you
> require, and things should work okay.
>
> Andrew
> --
> Ob disclaimer: Of course, I might be wrong...
>
> Guy Rauscher wrote:
> >
> > Hi!
> >
> > This bug exsited in the 3.0 version as well but I just found out about
> > it now. In certain cases (maybe its related to the use of numbers with a
> > decimal point) a while loop such as this: #while(I<1) loops one time too
> > many (as if it was #while(I<=1)). Just run the attached script.
> >
> > Guy
> >
> > ------------------------------------------------------------------------
>
> [most of example snipped]
>
> > // Doesn't work!
> > #declare T = 0;
> > #declare Tinterval = 0.1;
> > #while(T < 1)
> > #declare T = T + Tinterval;
> > #debug concat("T",str(T,1,1)," ")
> > #end
Odd, POVRay is supposed to do that already.
According to the docs "A value of 0.0 is false and any non-zero value is
true. Note that extremely small values of about 1e-10 are considered
zero in case of round off errors."
Post a reply to this message
|
|