X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/852a74a59b12d505eba86a0aed46bfe8af7b9acf..7f3f739fa4e1351a5b8a2dcd290f79c2e3baba38:/src/floatfns.c diff --git a/src/floatfns.c b/src/floatfns.c index 5c28677286..b5c8b4af5c 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -491,39 +491,27 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0, y = XINT (arg2); acc = 1; - if ((x == 0 && y != 0) || x == 1 || (x == -1 && (y & 1))) - return arg1; - if (x == -1) - y = 0; - - while (1) + if (y < 0) { - if (y & 1) - { - if (x < 0 - ? (acc < 0 - ? acc < MOST_POSITIVE_FIXNUM / x - : MOST_NEGATIVE_FIXNUM / x < acc) - : (acc < 0 - ? acc < MOST_NEGATIVE_FIXNUM / x - : MOST_POSITIVE_FIXNUM / x < acc)) - break; - acc *= x; - } - - y >>= 1; - if (y == 0) + if (x == 1) + acc = 1; + else if (x == -1) + acc = (y & 1) ? -1 : 1; + else + acc = 0; + } + else + { + while (y > 0) { - XSETINT (val, acc); - return val; + if (y & 1) + acc *= x; + x *= x; + y >>= 1; } - - if (x < 0 - ? x < MOST_POSITIVE_FIXNUM / x - : MOST_POSITIVE_FIXNUM / x < x) - break; - x *= x; } + XSETINT (val, acc); + return val; } f1 = FLOATP (arg1) ? XFLOAT_DATA (arg1) : XINT (arg1); f2 = FLOATP (arg2) ? XFLOAT_DATA (arg2) : XINT (arg2);