1
/* Test mpz_add, mpz_add_ui, mpz_cmp, mpz_cmp, mpz_mul, mpz_sqrtrem.
3
Copyright 1991, 1993, 1994, 1996, 2000, 2001 Free Software Foundation, Inc.
5
This file is part of the GNU MP Library.
7
The GNU MP Library is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
12
The GNU MP Library is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
29
void dump_abort _PROTO ((mpz_t, mpz_t, mpz_t));
30
void debug_mp _PROTO ((mpz_t, int));
33
main (int argc, char **argv)
41
gmp_randstate_ptr rands;
43
unsigned long size_range;
51
gmp_randseed_ui (rands, atoi (argv[1]));
59
for (i = 0; i < reps; i++)
61
mpz_urandomb (bs, rands, 32);
62
size_range = mpz_get_ui (bs) % 12 + 2; /* 0..8191 bit operands */
64
mpz_urandomb (bs, rands, size_range);
65
x2_size = mpz_get_ui (bs);
66
mpz_rrandomb (x2, rands, x2_size);
68
/* printf ("%ld\n", SIZ (x2)); */
70
mpz_sqrtrem (x, rem, x2);
73
/* Is square of result > argument? */
74
if (mpz_cmp (temp, x2) > 0)
75
dump_abort (x2, x, rem);
77
mpz_add_ui (temp2, x, 1);
78
mpz_mul (temp2, temp2, temp2);
80
/* Is square of (result + 1) <= argument? */
81
if (mpz_cmp (temp2, x2) <= 0)
82
dump_abort (x2, x, rem);
84
mpz_add (temp2, temp, rem);
86
/* Is the remainder wrong? */
87
if (mpz_cmp (x2, temp2) != 0)
88
dump_abort (x2, x, rem);
103
dump_abort (mpz_t x2, mpz_t x, mpz_t rem)
105
fprintf (stderr, "ERROR\n");
106
fprintf (stderr, "x2 = "); debug_mp (x2, -16);
107
fprintf (stderr, "x = "); debug_mp (x, -16);
108
fprintf (stderr, "remainder = "); debug_mp (rem, -16);
113
debug_mp (mpz_t x, int base)
115
mpz_out_str (stderr, base, x); fputc ('\n', stderr);