From 4572b3b9d5aa940b4337aa4f05f5df9773a7ba1f Mon Sep 17 00:00:00 2001 From: wbhart Date: Tue, 8 Dec 2009 01:59:11 +0000 Subject: [PATCH] Added test for exact square roots, --- tests/mpz/t-likely_prime_p.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/mpz/t-likely_prime_p.c b/tests/mpz/t-likely_prime_p.c index 4bf7c5f1..3dccc0ea 100644 --- a/tests/mpz/t-likely_prime_p.c +++ b/tests/mpz/t-likely_prime_p.c @@ -38,7 +38,7 @@ check_sqrt (void) mpz_init (x); gmp_randinit_default(rands); - for (i = 0; i < 2000000; i++) + for (i = 0; i < 200000; i++) { do { @@ -66,6 +66,30 @@ check_sqrt (void) abort(); } } + + for (i = 0; i < 200000; i++) + { + mpz_set_ui(x, GMP_NUMB_BITS/2 - 1); + mpz_urandomm(x, rands, x); + bits = mpz_get_ui(x) + 2; + mpz_rrandomb(x, rands, bits); + p = mpz_getlimbn(x, 0); + m = p*p; + + s = n_sqrt(m); + if (s != p) + { + printf ("mpz_likely_prime_p\n"); + printf ("n_sqrt is broken\n"); +#if defined( _MSC_VER ) && defined( _WIN64 ) + printf ("%llu is returned as n_sqrt(%llu)\n", s, m); +#else + printf ("%lu is returned as n_sqrt(%lu)\n", s, m); +#endif + abort(); + } + } + mpz_clear (x); gmp_randclear(rands); }