github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/tests/mpz/t-divis_2exp.c (about)

     1  /* test mpz_divisible_2exp_p */
     2  
     3  /*
     4  Copyright 2001 Free Software Foundation, Inc.
     5  
     6  This file is part of the GNU MP Library test suite.
     7  
     8  The GNU MP Library test suite is free software; you can redistribute it
     9  and/or modify it under the terms of the GNU General Public License as
    10  published by the Free Software Foundation; either version 3 of the License,
    11  or (at your option) any later version.
    12  
    13  The GNU MP Library test suite is distributed in the hope that it will be
    14  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    16  Public License for more details.
    17  
    18  You should have received a copy of the GNU General Public License along with
    19  the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
    20  
    21  #include <stdio.h>
    22  #include <stdlib.h>
    23  
    24  #include "gmp.h"
    25  #include "gmp-impl.h"
    26  #include "tests.h"
    27  
    28  
    29  void
    30  check_one (mpz_srcptr a, unsigned long d, int want)
    31  {
    32    int   got;
    33  
    34    got = (mpz_divisible_2exp_p (a, d) != 0);
    35    if (want != got)
    36      {
    37        printf ("mpz_divisible_2exp_p wrong\n");
    38        printf ("   expected %d got %d\n", want, got);
    39        mpz_trace ("   a", a);
    40        printf    ("   d=%lu\n", d);
    41        mp_trace_base = -16;
    42        mpz_trace ("   a", a);
    43        printf    ("   d=0x%lX\n", d);
    44        abort ();
    45      }
    46  }
    47  
    48  void
    49  check_data (void)
    50  {
    51    static const struct {
    52      const char    *a;
    53      unsigned long d;
    54      int           want;
    55  
    56    } data[] = {
    57  
    58      { "0", 0, 1 },
    59      { "0", 1, 1 },
    60      { "0", 2, 1 },
    61      { "0", 3, 1 },
    62  
    63      { "1", 0, 1 },
    64      { "1", 1, 0 },
    65      { "1", 2, 0 },
    66      { "1", 3, 0 },
    67      { "1", 10000, 0 },
    68  
    69      { "4", 0, 1 },
    70      { "4", 1, 1 },
    71      { "4", 2, 1 },
    72      { "4", 3, 0 },
    73      { "4", 4, 0 },
    74      { "4", 10000, 0 },
    75  
    76      { "0x80000000", 31, 1 },
    77      { "0x80000000", 32, 0 },
    78      { "0x80000000", 64, 0 },
    79  
    80      { "0x100000000", 32, 1 },
    81      { "0x100000000", 33, 0 },
    82      { "0x100000000", 64, 0 },
    83  
    84      { "0x8000000000000000", 63, 1 },
    85      { "0x8000000000000000", 64, 0 },
    86      { "0x8000000000000000", 128, 0 },
    87  
    88      { "0x10000000000000000", 64, 1 },
    89      { "0x10000000000000000", 65, 0 },
    90      { "0x10000000000000000", 128, 0 },
    91      { "0x10000000000000000", 256, 0 },
    92  
    93      { "0x10000000000000000100000000", 32, 1 },
    94      { "0x10000000000000000100000000", 33, 0 },
    95      { "0x10000000000000000100000000", 64, 0 },
    96  
    97      { "0x1000000000000000010000000000000000", 64, 1 },
    98      { "0x1000000000000000010000000000000000", 65, 0 },
    99      { "0x1000000000000000010000000000000000", 128, 0 },
   100      { "0x1000000000000000010000000000000000", 256, 0 },
   101      { "0x1000000000000000010000000000000000", 1024, 0 },
   102  
   103    };
   104  
   105    mpz_t   a, d;
   106    int     i;
   107  
   108    mpz_init (a);
   109    mpz_init (d);
   110  
   111    for (i = 0; i < numberof (data); i++)
   112      {
   113        mpz_set_str_or_abort (a, data[i].a, 0);
   114        check_one (a, data[i].d, data[i].want);
   115  
   116        mpz_neg (a, a);
   117        check_one (a, data[i].d, data[i].want);
   118      }
   119  
   120    mpz_clear (a);
   121    mpz_clear (d);
   122  }
   123  
   124  int
   125  main (int argc, char *argv[])
   126  {
   127    tests_start ();
   128  
   129    check_data ();
   130  
   131    tests_end ();
   132    exit (0);
   133  }