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