Annotation of OpenXM_contrib/gmp/mpn/generic/sizeinbase.c, Revision 1.1.1.1
1.1 ohara 1: /* mpn_sizeinbase -- approximation to chars required for an mpn.
2:
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.
6:
7: Copyright 1991, 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
8:
9: This file is part of the GNU MP Library.
10:
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 2.1 of the License, or (at your
14: option) any later version.
15:
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.
20:
21: You should have received a copy of the GNU Lesser General Public License
22: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
23: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24: MA 02111-1307, USA. */
25:
26: #include "gmp.h"
27: #include "gmp-impl.h"
28: #include "longlong.h"
29:
30:
31: /* Same as mpz_sizeinbase, meaning exact for power-of-2 bases, and either
32: exact or 1 too big for other bases. */
33:
34: size_t
35: mpn_sizeinbase (mp_srcptr xp, mp_size_t xsize, int base)
36: {
37: int lb_base, cnt;
38: mp_size_t totbits;
39:
40: ASSERT (xsize >= 0);
41: ASSERT (base >= 2);
42: ASSERT (base < numberof (__mp_bases));
43:
44: /* Special case for X == 0. */
45: if (xsize == 0)
46: return 1;
47:
48: /* Calculate the total number of significant bits of X. */
49: count_leading_zeros (cnt, xp[xsize-1]);
50: totbits = xsize * BITS_PER_MP_LIMB - cnt;
51:
52: if (POW2_P (base))
53: {
54: /* Special case for powers of 2, giving exact result. */
55: lb_base = __mp_bases[base].big_base;
56: return (totbits + lb_base - 1) / lb_base;
57: }
58: else
59: return (size_t) (totbits * __mp_bases[base].chars_per_bit_exactly) + 1;
60: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>