POV-Ray : Newsgroups : povray.newusers : rounding and logic functions : Re: rounding and logic functions Server Time
19 May 2024 14:31:40 EDT (-0400)
  Re: rounding and logic functions  
From: Alain
Date: 4 Aug 2013 22:01:43
Message: <51ff0787$1@news.povray.org>

> Alain <kua### [at] videotronca> wrote:

>>>
>>> I was doing a simple #if - #else - #end loop and trying to trigger an update
>>> once every "hour".
>>> #if ( Time1 = ceil ( Time1 ) )
>>>
>>
>> Using such a loop would only work for a *very* long parse operation as
>> it can only be evaluated during that time. When rendering or editing
>> your scene, the loop is never used.
>>
>>
>> Alain
>
> Well, the parse and render phases are something I need to better understand,
> because I long to do cool stuff with functions and macros, and I've seen that
> asked plenty of times.  Lots of reading and experiments for me.
>
> I used the loop in my render, and it seemed to work fine.
>
>    #if ( Time1 = ceil ( Time1 ) )
>     #declare A = A + B;
>     #declare B = B + 2;
>     text { ttf "arial.ttf" str (B, 3, 0) 0.1, 0 translate <Time1-2,
> Level1*Y_Factor+2, -0.4> pigment {color Yellow}}
>     #debug concat ("Time1 = ", str (Time1, 3, 1))
>     #debug "\n"
>     #debug concat ("A = ", str (A, 3, 1))
>     #debug "\n"
>    #else
>    #end // end if
>
> once I got the #if comparator right, it worked just like I expected it to.
>
> #if ( Time1 / Step = int (Time1/Step)  DID NOT work.
> Go figure.

It's probably due to some floating point rounding errors. If you have 
Time1=1000 and Step=10, then Time1/Step can result in something like 
99.9999999 that will show as 100 or 100.00001011 that also show as 100.
Now, int(99.999999) will evaluate as 99 whitch will fail the equality 
test with 99.999999.

That's because ALL calculations are performed as floating point and a 
division by 10 becomes a multiplication by 0.1, a value that can't be 
represented exactly using any floating point binary notation.
In fact, almost only values that are exact powers of 2 will give exact 
result in a division.
>
>

Your scene file is a text file.

The parse is the interpretation of the scene file. It goes over your 
code to find what to render.
It construct the actual data representing your scene in a totaly numeric 
form.
Once the parcing is termined, you can change and save your scene WITHOUT 
any effect on the resulting image. You can't save your modifications 
during the parse phase.

The rendering comes next, it's the step that actualy create the image 
that you can see from the numerical model created during the parse.



Alain


Post a reply to this message

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