This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pow(int , int)
- From: Gokhan Kisacikoglu <kisa at centropolisfx dot com>
- To: eduardoo at antar dot com dot mx
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 04 Dec 2002 15:55:46 -0800
- Subject: Re: pow(int , int)
- Organization: Centropolis Effects, LLC
- References: <20021204183243.96693.qmail@web11508.mail.yahoo.com>
- Reply-to: kisa at centropolisfx dot com
> so my question is :
>
> pow( ) does not support pow(int, int); ?
>
> just :
>
> long double std::pow(long double, int)
> float std::pow(float, int)
> double std::pow(double, int)
> long double std::pow(long double, long double)
> float std::pow(float, float)
>
Why is this such a big surprize to you? pow is mostly used to compute
the fractional powers (like 1.5, 0.25 etc) and it uses some sort of
Taylor or power series or something internally.
So, if you are trying to compute the integer powers, you are still
better off with the multiplication by itself as much as the power. I
guess you can still optimize that a bit by figuring out first the even
and odd powers etc;
3^15 = c * b * a
a = 3 * 3 = 3^2
b = a * a = 3^4
c = b * b = 3^8
saves you about 10 multiplications (5 instead of 15).
HTH,
Gokhan