::pow(T, n) vs std::pow(T, n) for non-constant n

Paolo Carlini pcarlini@suse.de
Sun Mar 14 13:02:00 GMT 2004


Richard Guenther wrote:

>> Yes, ::pow is more accurate in any case, but not always faster (faster
>> only when const arguments are involved)
>
> Yes, because the library does not know about the integer-ness of the 
> exponent.  This is why I suggest for __builtin_pow not to dispatch to 
> the library for non-const arguments, but to an internal routine 
> modeled after the v3 binary algorithm.

Ok, but at this point I have to finally agree with Gaby ;) that for 3.4 
probably
there isn't much we can do, if not:

double pow(double x, int n)
{
   if (__builtin_constant_p(n))
     return ::pow(x, n);
   else
     return __pow_helper(x, n);
}

which, as you say, can be considered "cheating" ;)

The best solution seems __builtin_powi... Is someone actually working on 
it???

Paolo.



More information about the Libstdc++ mailing list