+ if (scm_is_integer (y))
+ {
+ if (scm_is_true (scm_exact_p (y)))
+ return scm_integer_expt (x, y);
+ else
+ {
+ /* Here we handle the case where the exponent is an inexact
+ integer. We make the exponent exact in order to use
+ scm_integer_expt, and thus avoid the spurious imaginary
+ parts that may result from round-off errors in the general
+ e^(y log x) method below (for example when squaring a large
+ negative number). In this case, we must return an inexact
+ result for correctness. We also make the base inexact so
+ that scm_integer_expt will use fast inexact arithmetic
+ internally. Note that making the base inexact is not
+ sufficient to guarantee an inexact result, because
+ scm_integer_expt will return an exact 1 when the exponent
+ is 0, even if the base is inexact. */
+ return scm_exact_to_inexact
+ (scm_integer_expt (scm_exact_to_inexact (x),
+ scm_inexact_to_exact (y)));
+ }
+ }