POV-Ray : Newsgroups : povray.general : source code pow function : Re: source code pow function Server Time
3 Jul 2024 03:30:43 EDT (-0400)
  Re: source code pow function  
From: clipka
Date: 9 Aug 2015 14:25:33
Message: <55c79b1d$1@news.povray.org>
Am 08.08.2015 um 07:48 schrieb Anthony D. Baye:
> Does the source actually use the default power function from the cmath library?

To be precise, POV-Ray uses the "pow()" function declared in the 
standard <cmath> header file; what library this function is implemented 
in depends on the compiler and runtime environment.

For instance, and AFAIK, when compiling with Microsoft Visual Studio the 
function is implemented in the "tran.lib" library, while on Unix systems 
it is implemented in a library called "libm".

> It seems to me that I heard the default algorithm was actually somewhat
> inefficient.

That may well be: The default algorithm needs to fit certain precision 
constraints, /and/ be somewhat efficient in /all/ cases, so it is 
inevitable that there are cases in which a less-precise or less-generic 
algorithm would suffice and be faster.

Also, it may depend on the actual math library linked to, and/or the CPU 
architecture on which it is executed.


That said, the total time POV-Ray spends executing calls to pow() is 
probably far too low to warrant spending any energy on trying to figure 
out which of those calls can be replaced with a faster implementation. 
By far, most exponentiation in raytracing is squaring and taking the 
square root, for which POV-Ray already uses specialized functions 
(currently the "x*x" idiom in the case of squaring, and the sqrt() 
function from <cmath> for taking the square root).

Likewise, looking at the SDL pow() function, POV-Ray spends far more 
time parsing the SDL statement than it does actually computing the result.


Bottom line: Optimization /may/ be possible, but I strongly suspect it's 
not worth bothering. I presume it isn't even worth bothering to examine 
whether it is worth bothering.


Post a reply to this message

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