pow() function question
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Nov 27 08:56:52 PST 2007
"aeschere" <aeschere at nospam.cryptobit.org> wrote in message
news:fiheps$2m28$1 at digitalmars.com...
>I am relatively new to D. So far, I really like it. However, I need to
> do some power functions on integers. Is pow() the only way of
> performing this type of function? It seems silly to have to either use
> reals for integer work. This was one of my gripes with C's pow()
> function. I check the news archives and noticed there was talk of
> creating a '**' power function for integers back in 2005. I tried it but
> it didn't work.
>
> Michael
> (remove nospam if you need to get a hold of me personally)
If you're using phobos, std.math.pow has an overload for integral exponents.
Although I think it's only highly optimized for lower powers, like up to the
third or fourth; anything higher and I think it uses floating point numbers.
Keep in mind that floating point performance on modern processors is not
exactly slow. Doing a power operation (which involves.. what, a ln?
something like that) might be faster than a loop that multiplies the
integers over and over.
More information about the Digitalmars-d-learn
mailing list