POV-Ray : Newsgroups : povray.general : optimisation of functions - how to? : optimisation of functions - how to? Server Time
30 Jul 2024 02:26:35 EDT (-0400)
  optimisation of functions - how to?  
From: makc
Date: 19 Jan 2010 18:35:00
Message: <web.4b563f9c3efa46efa2b7633a0@news.povray.org>
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?

Ok, in this particular case I could use intermediate function

#declare menger2 = function (tmp) {
   floor (3*tmp) - floor (3*tmp/2)*2
}

#declare menger = function (x, order) {
   menger2(frac(x*pow(3,order)))
}

but

1) not sure if this can be done for arbitrary combination
2) wont stacking functions like that actually slow things down

Thanks.


Post a reply to this message

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