aboutsummaryrefslogtreecommitdiffstats
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert2011-10-06 00:51:21 -0700
committerPaul Eggert2011-10-06 00:51:21 -0700
commit8d1da888c6f3c6763c7e6e73a5bdd3bf997d0cfc (patch)
treec34676d36a1f213d2c3bb70c164941ae085eb41f /src/floatfns.c
parentdf52aeb91d63c3f904c717fa8897e59fd9a5a557 (diff)
downloademacs-8d1da888c6f3c6763c7e6e73a5bdd3bf997d0cfc.tar.gz
emacs-8d1da888c6f3c6763c7e6e73a5bdd3bf997d0cfc.zip
* floatfns.c (Fexpt): Avoid unnecessary multiplications.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c23
1 files 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,
490 490
491 x = XINT (arg1); 491 x = XINT (arg1);
492 y = XINT (arg2); 492 y = XINT (arg2);
493 acc = 1; 493 acc = (y & 1 ? x : 1);
494 494
495 if (y < 0) 495 while ((y >>= 1) != 0)
496 { 496 {
497 if (x == 1) 497 x *= x;
498 acc = 1; 498 if (y & 1)
499 else if (x == -1) 499 acc *= x;
500 acc = (y & 1) ? -1 : 1;
501 else
502 acc = 0;
503 }
504 else
505 {
506 while (y > 0)
507 {
508 if (y & 1)
509 acc *= x;
510 x *= x;
511 y >>= 1;
512 }
513 } 500 }
514 XSETINT (val, acc); 501 XSETINT (val, acc);
515 return val; 502 return val;