summaryrefslogtreecommitdiff
path: root/mpf/pow_ui.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>1999-12-08 19:56:31 +0100
committertege <tege@gmplib.org>1999-12-08 19:56:31 +0100
commit80cad2650360e7399e44bfc01a5a203386cd91ad (patch)
tree49ef49f9caf3c23ccc242727b1d65aeee4b0d9f2 /mpf/pow_ui.c
parente4ff1dfb4e8a71d258f7e46aea6cec3278caf498 (diff)
downloadgmp-80cad2650360e7399e44bfc01a5a203386cd91ad.tar.gz
Avoid final squaring in loop.
Diffstat (limited to 'mpf/pow_ui.c')
-rw-r--r--mpf/pow_ui.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mpf/pow_ui.c b/mpf/pow_ui.c
index 52e00e2f2..8737253d0 100644
--- a/mpf/pow_ui.c
+++ b/mpf/pow_ui.c
@@ -33,17 +33,19 @@ mpf_pow_ui (r, b, e)
#endif
{
mpf_t b2;
+ unsigned long int e2;
mpf_init2 (b2, mpf_get_prec (r));
mpf_set (b2, b);
mpf_set_ui (r, 1);
- while (e != 0)
+ if ((e & 1) != 0)
+ mpf_set (r, b2);
+ for (e2 = e >> 1; e2 != 0; e2 >>= 1)
{
- if ((e & 1) != 0)
- mpf_mul (r, r, b2);
mpf_mul (b2, b2, b2);
- e >>= 1;
+ if ((e2 & 1) != 0)
+ mpf_mul (r, r, b2);
}
mpf_clear (b2);