POV-Ray : Newsgroups : povray.general : optimisation of functions - how to? : Re: optimisation of functions - how to? Server Time
30 Jul 2024 02:20:14 EDT (-0400)
  Re: optimisation of functions - how to?  
From: Thorsten Froehlich
Date: 20 Jan 2010 06:45:31
Message: <4b56ecdb@news.povray.org>
On 20.01.10 00:33, makc wrote:
> Hello all, could you please advice on following problem. For example, I have two
> functions
>
> #declare frac = function (x) {
>     x - floor (x)
> }
>
> #declare menger = function (x, order) {
>     floor (3*frac(x*pow(3,order))) - floor (3*frac(x*pow(3,order))/2)*2
> }
>
> In procedural language like C++ to avoid recalculation of frac/pow I would write
> in 2nd function
>
> double tmp = frac(x*pow(3,order));
> return floor (3*tmp) - floor (3*tmp/2)*2;
>
> But how do I explain this to pov?

You don't need a second function to declare a variable. While it is probably 
the easiest to read, if you really want you can reuse the sum or prod 
functions. In the documentation, i.e. at 
<http://www.povray.org/documentation/view/3.6.1/231/> you can find a few 
examples. The trick here is of course to reuse the iteration variable.

	Thorsten


Post a reply to this message

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