1 /* Test mpz_sizeinbase.
3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 /* Disabled due to the bogosity of trying to fake an _mp_d pointer to
29 below an object. Has been seen to fail on a hppa system and on ia64. */
32 /* Create a fake mpz consisting of just a single 1 bit, with totbits being
33 the total number of bits, inclusive of that 1 bit. */
35 mpz_fake_bits (mpz_ptr z, unsigned long totbits)
38 unsigned long zero_bits, zero_limbs;
40 zero_bits = totbits - 1;
41 zero_limbs = zero_bits / GMP_NUMB_BITS;
42 zero_bits %= GMP_NUMB_BITS;
44 SIZ(z) = zero_limbs + 1;
45 PTR(z) = (&n) - (SIZ(z) - 1);
46 n = CNST_LIMB(1) << zero_bits;
48 ASSERT_ALWAYS (mpz_sizeinbase (z, 2) == totbits);
52 /* This was seen to fail on a GNU/Linux powerpc32 with gcc 2.95.2,
53 apparently due to a doubtful value of mp_bases[10].chars_per_bit_exactly
54 (0X1.34413509F79FDP-2 whereas 0X1.34413509F79FFP-2 is believed correct).
55 Presumably this is a glibc problem when gcc converts the decimal string
56 in mp_bases.c, or maybe it's only a function of the rounding mode during
61 unsigned long totbits = 198096465;
63 size_t want = 59632979;
67 mpz_fake_bits (z, totbits);
68 got = mpz_sizeinbase (z, base);
71 printf ("mpz_sizeinbase\n");
72 printf (" base %d\n", base);
73 printf (" totbits %lu\n", totbits);
74 printf (" got %u\n", got);
75 printf (" want %u\n", want);
86 /* check_sample (); */