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

Gabriel Dos Reis gdr@integrable-solutions.net
Sun Mar 14 20:47:00 GMT 2004


Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:

| I'm not at all surprised if ::pow() gets to call libm - because libm
| pow is (double, double) here and has to fall back to taylor series pow
| approximation probably.  There is no integer overload in libm.

There is no overload for integer exponent -- as traditionally libm
seems to contain only "C" functions.  Most implementations I've
seen tried to see whether the exponent is integer or not and implement
a "different" algorithm. Some simply don't.  The standard function
std::pow(T, int) was introduced to handle that case. 

| So we can again cheat by using something like
| 
| double pow(double x, int n)
| {
|     if (__builtin_constant_p(n))
|       return __builtin_pow(x, n);
|     else
|       return __pow_helper(x, n);

I don't think we should be giving different results based on
"constantness". 

| or do the right thing with a special __builtin_powi() or use a
| pow_helper in libgcc to which we can dispatch from __bultin_pow() in
| non-optimized/inlined integer exponent case.

If you want to have support for this in the compiler, please work on
__builtin_powi() and the like -- as was discussed last summer.

-- Gaby



More information about the Libstdc++ mailing list