summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2009-04-13 12:06:15 +0200
committerTorbjorn Granlund <tege@gmplib.org>2009-04-13 12:06:15 +0200
commit4ba4102fb0ebe68d0365b1c5778df841730f7109 (patch)
tree8d2c1339d9d5dd2d6619adf60391a8eabf803317
parent68955439d89f3ea73df2d60ed13a624563097184 (diff)
downloadgmp-4ba4102fb0ebe68d0365b1c5778df841730f7109.tar.gz
Rewrite. Add unconditional gcc 4.3.2 tests.
-rw-r--r--tests/mpz/t-root.c119
1 files changed, 66 insertions, 53 deletions
diff --git a/tests/mpz/t-root.c b/tests/mpz/t-root.c
index 18d7f2cdf..86af70e59 100644
--- a/tests/mpz/t-root.c
+++ b/tests/mpz/t-root.c
@@ -1,6 +1,6 @@
-/* Test mpz_add, mpz_add_ui, mpz_cmp, mpz_cmp, mpz_mul, mpz_sqrtrem.
+/* Test mpz_root, mpz_rootrem, and mpz_perfect_power_p.
-Copyright 1991, 1993, 1994, 1996, 2000, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2009 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -26,12 +26,68 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
void debug_mp __GMP_PROTO ((mpz_t, int));
+void
+check_one (mpz_t root1, mpz_t x2, unsigned long nth, int i)
+{
+ mpz_t temp, temp2;
+ mpz_t root2, rem2;
+
+ mpz_init (root2);
+ mpz_init (rem2);
+ mpz_init (temp);
+ mpz_init (temp2);
+
+ mpz_rootrem (root2, rem2, x2, nth);
+ mpz_pow_ui (temp, root1, nth);
+ mpz_add (temp2, temp, rem2);
+
+ /* Is power of result > argument? */
+ if (mpz_cmp (root1, root2) != 0 || mpz_cmp (x2, temp2) != 0 || mpz_cmp (temp, x2) > 0)
+ {
+ fprintf (stderr, "ERROR after test %d\n", i);
+ debug_mp (x2, 10);
+ debug_mp (root1, 10);
+ debug_mp (root2, 10);
+ fprintf (stderr, "nth: %lu\n", nth);
+ abort ();
+ }
+
+ if (nth > 1 && mpz_cmp_ui (temp, 1L) > 0 && ! mpz_perfect_power_p (temp))
+ {
+ fprintf (stderr, "ERROR in mpz_perfect_power_p after test %d\n", i);
+ debug_mp (temp, 10);
+ debug_mp (root1, 10);
+ fprintf (stderr, "nth: %lu\n", nth);
+ abort ();
+ }
+
+ if (nth <= 10000) /* skip too expensive test */
+ {
+ mpz_add_ui (temp2, root1, 1L);
+ mpz_pow_ui (temp2, temp2, nth);
+
+ /* Is square of (result + 1) <= argument? */
+ if (mpz_cmp (temp2, x2) <= 0)
+ {
+ fprintf (stderr, "ERROR after test %d\n", i);
+ debug_mp (x2, 10);
+ debug_mp (root1, 10);
+ fprintf (stderr, "nth: %lu\n", nth);
+ abort ();
+ }
+ }
+
+ mpz_clear (root2);
+ mpz_clear (rem2);
+ mpz_clear (temp);
+ mpz_clear (temp2);
+}
+
int
main (int argc, char **argv)
{
mpz_t x2;
- mpz_t root1, root2, rem2;
- mpz_t temp, temp2;
+ mpz_t root1;
mp_size_t x2_size;
int i;
int reps = 5000;
@@ -50,10 +106,11 @@ main (int argc, char **argv)
mpz_init (x2);
mpz_init (root1);
- mpz_init (root2);
- mpz_init (rem2);
- mpz_init (temp);
- mpz_init (temp2);
+
+ /* This triggers a gcc 4.3.2 bug */
+ mpz_set_str (x2, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000000000000002", 16);
+ mpz_root (root1, x2, 2);
+ check_one (root1, x2, 2, -1);
for (i = 0; i < reps; i++)
{
@@ -85,56 +142,12 @@ main (int argc, char **argv)
mpz_root (root1, x2, nth);
}
- /* printf ("%ld %lu\n", SIZ (x2), nth); */
-
- mpz_rootrem (root2, rem2, x2, nth);
- mpz_pow_ui (temp, root1, nth);
- mpz_add (temp2, temp, rem2);
-
- /* Is power of result > argument? */
- if (mpz_cmp (root1, root2) != 0 || mpz_cmp (x2, temp2) != 0 || mpz_cmp (temp, x2) > 0)
- {
- fprintf (stderr, "ERROR after test %d\n", i);
- debug_mp (x2, 10);
- debug_mp (root1, 10);
- debug_mp (root2, 10);
- fprintf (stderr, "nth: %lu\n", nth);
- abort ();
- }
-
- if (nth > 1 && mpz_cmp_ui (temp, 1L) > 0 && ! mpz_perfect_power_p (temp))
- {
- fprintf (stderr, "ERROR in mpz_perfect_power_p after test %d\n", i);
- debug_mp (temp, 10);
- debug_mp (root1, 10);
- fprintf (stderr, "nth: %lu\n", nth);
- abort ();
- }
-
- if (nth > 10000)
- continue; /* skip too expensive test */
-
- mpz_add_ui (temp2, root1, 1L);
- mpz_pow_ui (temp2, temp2, nth);
-
- /* Is square of (result + 1) <= argument? */
- if (mpz_cmp (temp2, x2) <= 0)
- {
- fprintf (stderr, "ERROR after test %d\n", i);
- debug_mp (x2, 10);
- debug_mp (root1, 10);
- fprintf (stderr, "nth: %lu\n", nth);
- abort ();
- }
+ check_one (root1, x2, nth, i);
}
mpz_clear (bs);
mpz_clear (x2);
mpz_clear (root1);
- mpz_clear (root2);
- mpz_clear (rem2);
- mpz_clear (temp);
- mpz_clear (temp2);
tests_end ();
exit (0);