If either argument is a floating-point number, and x is non-negative
(i.e. the result is real), I use the C function pow() to implement
exponentiation in my language. I don't care whether C pow() implements
it as exp(x*ln(y)), or as a machine instruction for exponentiation,
or as something else.
For two integers with a positive base my implementation uses
mpz_pow_ui() and mpz_ui_pow_ui() from the GMP library. Again I don't
care how it computes it, perhaps by repeated multiplication and
squaring according to bits of the exponent, but I'm sure it doesn't
use logarithms.
These two are the only "core" implementations I use. They are wrapped
by appropriate formulas when the arguments or the result are exact
non-integer rational numbers or non-real complex numbers.
--
__("< Marcin Kowalczyk
\__/ qrc...@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
int^int:
I use a loop (ideal would be to hard-code some of these cases, but I will
argue that, in general, exponents aren't that common, so it is not really
needed imo).
then again, such an optimization could always be added as a minor compiler
hack, and I could utilize pre-existing bytecodes, eg:
int x;
...
x^3
load x
dup_f
dup_f
mul_fn
mul_fn
which is probably better than nothing...
float^float:
I use pow (except when the output will be complex, eg, with a negative base
and non-integer exponent, ...).
complex^float
float^complex
complex^complex
I use more "involved" calculations...