diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-02-28 23:10:40 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-02-28 23:10:40 +0100 |
commit | c61d512fe1d4364b1c1a0975496b7d9922b17969 (patch) | |
tree | c5341f31d6ff513b01d7edd95f0c4e03847dd159 /tests/refmpz.c | |
parent | de68b315f48d6e7cdd1fcd39645587a116ecd993 (diff) | |
download | gmp-c61d512fe1d4364b1c1a0975496b7d9922b17969.tar.gz |
* tests/refmpz.c (refmpz_pow_ui): Copied from tests/mpz/t-pow_ui.c
Diffstat (limited to 'tests/refmpz.c')
-rw-r--r-- | tests/refmpz.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/refmpz.c b/tests/refmpz.c index 5b9fc1367..58ad67371 100644 --- a/tests/refmpz.c +++ b/tests/refmpz.c @@ -1,7 +1,7 @@ /* Reference mpz functions */ /* -Copyright 2000, 2001 Free Software Foundation, Inc. +Copyright 1997, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -197,3 +197,29 @@ refmpz_si_kronecker (long a, mpz_srcptr b) mpz_clear (az); return ret; } + + +void +refmpz_pow_ui (mpz_ptr w, mpz_srcptr b, unsigned long e) +{ + mpz_t s, t; + unsigned long i; + + mpz_init_set_ui (t, 1L); + mpz_init_set (s, b); + + if ((e & 1) != 0) + mpz_mul (t, t, s); + + for (i = 2; i <= e; i <<= 1) + { + mpz_mul (s, s, s); + if ((i & e) != 0) + mpz_mul (t, t, s); + } + + mpz_set (w, t); + + mpz_clear (s); + mpz_clear (t); +} |