summaryrefslogtreecommitdiff
path: root/tests/mpf
diff options
context:
space:
mode:
authorTorbjorn Granlund <torbjorng@google.com>2015-10-28 22:04:21 +0100
committerTorbjorn Granlund <torbjorng@google.com>2015-10-28 22:04:21 +0100
commit840736d7c0cc533f5911bd8c2c8f20aa0ba9b0f5 (patch)
tree5a065698e1ceacb6036e601b74927771b07acab9 /tests/mpf
parent92af88721b44634fd8173c08bf0c9078543da42e (diff)
downloadgmp-840736d7c0cc533f5911bd8c2c8f20aa0ba9b0f5.tar.gz
Add elementary testing of mpf_pow_ui.
Diffstat (limited to 'tests/mpf')
-rw-r--r--tests/mpf/Makefile.am4
-rw-r--r--tests/mpf/t-pow_ui.c68
2 files changed, 70 insertions, 2 deletions
diff --git a/tests/mpf/Makefile.am b/tests/mpf/Makefile.am
index ed1c72667..08630ddf9 100644
--- a/tests/mpf/Makefile.am
+++ b/tests/mpf/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to generate Makefile.in
-# Copyright 1996, 1999-2004 Free Software Foundation, Inc.
+# Copyright 1996, 1999-2004, 2015 Free Software Foundation, Inc.
#
# This file is part of the GNU MP Library test suite.
#
@@ -24,7 +24,7 @@ LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la
check_PROGRAMS = t-dm2exp t-conv t-add t-sub t-sqrt t-sqrt_ui t-muldiv reuse \
t-cmp_d t-cmp_si t-div t-fits t-get_d t-get_d_2exp \
t-get_si t-get_ui t-gsprec t-inp_str t-int_p t-mul_ui \
- t-set t-set_q t-set_si t-set_ui t-trunc t-ui_div t-eq
+ t-set t-set_q t-set_si t-set_ui t-trunc t-ui_div t-eq t-pow_ui
TESTS = $(check_PROGRAMS)
$(top_builddir)/tests/libtests.la:
diff --git a/tests/mpf/t-pow_ui.c b/tests/mpf/t-pow_ui.c
new file mode 100644
index 000000000..214c9b781
--- /dev/null
+++ b/tests/mpf/t-pow_ui.c
@@ -0,0 +1,68 @@
+/* Test mpf_pow_ui
+
+Copyright 2015 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite is distributed in the hope that it will be
+useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+void
+check_data (void)
+{
+ unsigned int b, e;
+ mpf_t b1, r, r2;
+
+ mpf_inits (b1, r, r2, NULL);
+
+ /* This test just test integers with results that fit in a single
+ limb. This avoid any rounding. */
+
+ for (b = 0; b <= 400; b++)
+ {
+ mpf_set_ui (b1, b);
+ mpf_set_ui (r2, 1);
+ for (e = 0; e <= GMP_LIMB_BITS; e++)
+ {
+ mpf_pow_ui (r, b1, e);
+
+ if (mpf_cmp_ui (r, ~CNST_LIMB(0)) > 0)
+ break;
+
+ if (mpf_cmp (r, r2))
+ abort ();
+
+ mpf_mul_ui (r2, r2, b);
+ }
+ }
+
+ mpf_clears (b1, r, r2, NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+ tests_start ();
+
+ check_data ();
+
+ tests_end ();
+ exit (0);
+}