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-impl.h"
24 #include "tests.h"
25
26 void
check_data(void)27 check_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
60 int
main(int argc,char ** argv)61 main (int argc, char **argv)
62 {
63 tests_start ();
64
65 check_data ();
66
67 tests_end ();
68 exit (0);
69 }
70