Blame tests/mpz/t-sizeinbase.c

Packit 5c3484
/* Test mpz_sizeinbase.
Packit 5c3484
Packit 5c3484
Copyright 2001, 2002 Free Software Foundation, Inc.
Packit 5c3484
Packit 5c3484
This file is part of the GNU MP Library test suite.
Packit 5c3484
Packit 5c3484
The GNU MP Library test suite is free software; you can redistribute it
Packit 5c3484
and/or modify it under the terms of the GNU General Public License as
Packit 5c3484
published by the Free Software Foundation; either version 3 of the License,
Packit 5c3484
or (at your option) any later version.
Packit 5c3484
Packit 5c3484
The GNU MP Library test suite is distributed in the hope that it will be
Packit 5c3484
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5c3484
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 5c3484
Public License for more details.
Packit 5c3484
Packit 5c3484
You should have received a copy of the GNU General Public License along with
Packit 5c3484
the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
Packit 5c3484
Packit 5c3484
#include <stdio.h>
Packit 5c3484
#include <stdlib.h>
Packit 5c3484
#include "gmp.h"
Packit 5c3484
#include "gmp-impl.h"
Packit 5c3484
#include "tests.h"
Packit 5c3484
Packit 5c3484
Packit 5c3484
#if 0
Packit 5c3484
  /* Disabled due to the bogosity of trying to fake an _mp_d pointer to
Packit 5c3484
     below an object.  Has been seen to fail on a hppa system and on ia64.  */
Packit 5c3484
Packit 5c3484
Packit 5c3484
/* Create a fake mpz consisting of just a single 1 bit, with totbits being
Packit 5c3484
   the total number of bits, inclusive of that 1 bit.  */
Packit 5c3484
void
Packit 5c3484
mpz_fake_bits (mpz_ptr z, unsigned long totbits)
Packit 5c3484
{
Packit 5c3484
  static mp_limb_t  n;
Packit 5c3484
  unsigned long     zero_bits, zero_limbs;
Packit 5c3484
Packit 5c3484
  zero_bits = totbits - 1;
Packit 5c3484
  zero_limbs = zero_bits / GMP_NUMB_BITS;
Packit 5c3484
  zero_bits %= GMP_NUMB_BITS;
Packit 5c3484
Packit 5c3484
  SIZ(z) = zero_limbs + 1;
Packit 5c3484
  PTR(z) = (&n) - (SIZ(z) - 1);
Packit 5c3484
  n = CNST_LIMB(1) << zero_bits;
Packit 5c3484
Packit 5c3484
  ASSERT_ALWAYS (mpz_sizeinbase (z, 2) == totbits);
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
Packit 5c3484
/* This was seen to fail on a GNU/Linux powerpc32 with gcc 2.95.2,
Packit 5c3484
   apparently due to a doubtful value of mp_bases[10].chars_per_bit_exactly
Packit 5c3484
   (0X1.34413509F79FDP-2 whereas 0X1.34413509F79FFP-2 is believed correct).
Packit 5c3484
   Presumably this is a glibc problem when gcc converts the decimal string
Packit 5c3484
   in mp_bases.c, or maybe it's only a function of the rounding mode during
Packit 5c3484
   compilation.  */
Packit 5c3484
void
Packit 5c3484
check_sample (void)
Packit 5c3484
{
Packit 5c3484
  unsigned long  totbits = 198096465;
Packit 5c3484
  int        base = 10;
Packit 5c3484
  size_t     want = 59632979;
Packit 5c3484
  size_t     got;
Packit 5c3484
  mpz_t      z;
Packit 5c3484
Packit 5c3484
  mpz_fake_bits (z, totbits);
Packit 5c3484
  got = mpz_sizeinbase (z, base);
Packit 5c3484
  if (got != want)
Packit 5c3484
    {
Packit 5c3484
      printf ("mpz_sizeinbase\n");
Packit 5c3484
      printf ("  base    %d\n",  base);
Packit 5c3484
      printf ("  totbits %lu\n", totbits);
Packit 5c3484
      printf ("  got     %u\n",  got);
Packit 5c3484
      printf ("  want    %u\n",  want);
Packit 5c3484
      abort ();
Packit 5c3484
    }
Packit 5c3484
}
Packit 5c3484
#endif
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
main (void)
Packit 5c3484
{
Packit 5c3484
  tests_start ();
Packit 5c3484
Packit 5c3484
  /* check_sample (); */
Packit 5c3484
Packit 5c3484
  tests_end ();
Packit 5c3484
  exit (0);
Packit 5c3484
}