From 8d1da888c6f3c6763c7e6e73a5bdd3bf997d0cfc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 6 Oct 2011 00:51:21 -0700 Subject: [PATCH] * floatfns.c (Fexpt): Avoid unnecessary multiplications. --- src/floatfns.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/floatfns.c b/src/floatfns.c index 6158b9bd26d..f8b775011ae 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -490,26 +490,13 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0, x = XINT (arg1); y = XINT (arg2); - acc = 1; + acc = (y & 1 ? x : 1); - if (y < 0) + while ((y >>= 1) != 0) { - if (x == 1) - acc = 1; - else if (x == -1) - acc = (y & 1) ? -1 : 1; - else - acc = 0; - } - else - { - while (y > 0) - { - if (y & 1) - acc *= x; - x *= x; - y >>= 1; - } + x *= x; + if (y & 1) + acc *= x; } XSETINT (val, acc); return val; -- 2.39.2