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

     1  /* Test mpf_pow_ui
     2  
     3  Copyright 2015 Free Software Foundation, Inc.
     4  
     5  This file is part of the GNU MP Library test suite.
     6  
     7  The GNU MP Library test suite is free software; you can redistribute it
     8  and/or modify it under the terms of the GNU General Public License as
     9  published by the Free Software Foundation; either version 3 of the License,
    10  or (at your option) any later version.
    11  
    12  The GNU MP Library test suite is distributed in the hope that it will be
    13  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    15  Public License for more details.
    16  
    17  You should have received a copy of the GNU General Public License along with
    18  the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
    19  
    20  #include <stdio.h>
    21  #include <stdlib.h>
    22  
    23  #include "gmp.h"
    24  #include "gmp-impl.h"
    25  #include "tests.h"
    26  
    27  void
    28  check_data (void)
    29  {
    30    unsigned int b, e;
    31    mpf_t b1, r, r2, limit;
    32  
    33    mpf_inits (b1, r, r2, NULL);
    34    mpf_init_set_ui (limit, 1);
    35    mpf_mul_2exp (limit, limit, MAX (GMP_NUMB_BITS, 53)); 
    36  
    37    /* This test just test integers with results that fit in a single
    38       limb or 53 bits.  This avoids any rounding.  */
    39  
    40    for (b = 0; b <= 400; b++)
    41      {
    42        mpf_set_ui (b1, b);
    43        mpf_set_ui (r2, 1);
    44        for (e = 0; e <= GMP_LIMB_BITS; e++)
    45  	{
    46  	  mpf_pow_ui (r, b1, e);
    47  
    48  	  if (mpf_cmp (r, r2))
    49  	    abort ();
    50  
    51  	  mpf_mul_ui (r2, r2, b);
    52  
    53  	  if (mpf_cmp (r2, limit) >= 0)
    54  	    break;
    55  	}
    56      }
    57  
    58    mpf_clears (b1, r, r2, limit, NULL);
    59  }
    60  
    61  int
    62  main (int argc, char **argv)
    63  {
    64    tests_start ();
    65  
    66    check_data ();
    67  
    68    tests_end ();
    69    exit (0);
    70  }