summaryrefslogtreecommitdiff
path: root/mpz/sizeinbase.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2002-01-23 22:24:05 +0100
committerKevin Ryde <user42@zip.com.au>2002-01-23 22:24:05 +0100
commit595eaa16b6356c3a93bfc3472606de839d132592 (patch)
tree1f53085053bf353c297632700902e49867cfe7b8 /mpz/sizeinbase.c
parent6983958e65ccaabfe6bd2490efbb50766720360d (diff)
downloadgmp-595eaa16b6356c3a93bfc3472606de839d132592.tar.gz
* mpn/generic/sizeinbase.c: New file, adapted from mpz/sizeinbase.c.
Use POW2_P, use __mp_bases[base].big_base for log2(base). * mpz/sizeinbase.c, tune/speed.h, mpn/generic/get_str.c, mpz/get_str.c, mpbsd/mtox.c: Use it.
Diffstat (limited to 'mpz/sizeinbase.c')
-rw-r--r--mpz/sizeinbase.c26
1 files changed, 2 insertions, 24 deletions
diff --git a/mpz/sizeinbase.c b/mpz/sizeinbase.c
index dee647083..0028e28c3 100644
--- a/mpz/sizeinbase.c
+++ b/mpz/sizeinbase.c
@@ -2,7 +2,7 @@
character the integer X would have printed in base BASE. The
approximation is never too small.
-Copyright 1991, 1993, 1994, 1995, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -28,27 +28,5 @@ MA 02111-1307, USA. */
size_t
mpz_sizeinbase (mpz_srcptr x, int base)
{
- mp_size_t size = ABS (x->_mp_size);
- int lb_base, cnt;
- size_t totbits;
-
- /* Special case for X == 0. */
- if (size == 0)
- return 1;
-
- /* Calculate the total number of significant bits of X. */
- count_leading_zeros (cnt, x->_mp_d[size - 1]);
- totbits = size * BITS_PER_MP_LIMB - cnt;
-
- if ((base & (base - 1)) == 0)
- {
- /* Special case for powers of 2, giving exact result. */
-
- count_leading_zeros (lb_base, base);
- lb_base = BITS_PER_MP_LIMB - lb_base - 1;
-
- return (totbits + lb_base - 1) / lb_base;
- }
- else
- return (size_t) (totbits * __mp_bases[base].chars_per_bit_exactly) + 1;
+ return mpn_sizeinbase (PTR(x), ABSIZ(x), base);
}