1 /* mpn_sizeinbase -- approximation to chars required for an mpn.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 1991, 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
29 /* Same as mpz_sizeinbase, meaning exact for power-of-2 bases, and either
30 exact or 1 too big for other bases. */
33 mpn_sizeinbase (mp_srcptr xp, mp_size_t xsize, int base)
40 ASSERT (base < numberof (__mp_bases));
42 /* Special case for X == 0. */
46 /* Calculate the total number of significant bits of X. */
47 count_leading_zeros (cnt, xp[xsize-1]);
48 totbits = xsize * BITS_PER_MP_LIMB - cnt;
52 /* Special case for powers of 2, giving exact result. */
53 lb_base = __mp_bases[base].big_base;
54 return (totbits + lb_base - 1) / lb_base;
57 return (size_t) (totbits * __mp_bases[base].chars_per_bit_exactly) + 1;