|
![](/i/fill.gif) |
Le 2011/08/04 18:00, clipka a écrit :
>
> My favorite solution to such issues is to replace, e.g.,
>
> #declare F = function(a) { sin(a) + cos(a) + sin(a)*cos(a) }
>
> with
>
> #declare F_ = function(sina,cosa) { sina + cosa + sina*cosa }
> #declare F = function(a) { F_(sin(a),cos(a)) }
>
> The idea is to create a helper function where all the multiply-used
> sub-expressions are substituted by parameters, and have a main function
> that computes these sub-expressions and passes them to that helper
> function. I think it's sufficiently easy to read if you use good names
> for the sub-expressions.
>
You are probably also geting some performance improvement that way: The
sin() and cos() functions are now only evaluated once, then you pass the
returned values to the helper function.
Alain
Post a reply to this message
|
![](/i/fill.gif) |