Annotation of OpenXM_contrib/gmp/tests/mpz/dive.c, Revision 1.1
1.1 ! ohara 1: /* Test mpz_mul, mpz_divexact.
! 2:
! 3: Copyright 1996, 2001, 2002 Free Software Foundation, Inc.
! 4:
! 5: This file is part of the GNU MP Library.
! 6:
! 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.
! 11:
! 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.
! 16:
! 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. */
! 21:
! 22: #include <stdio.h>
! 23: #include <stdlib.h>
! 24:
! 25: #include "gmp.h"
! 26: #include "gmp-impl.h"
! 27: #include "tests.h"
! 28:
! 29: int
! 30: main (int argc, char **argv)
! 31: {
! 32: mpz_t op1, op2;
! 33: mpz_t prod, quot;
! 34: mp_size_t size;
! 35: int i;
! 36: int reps = 20000;
! 37: gmp_randstate_ptr rands;
! 38: mpz_t bs;
! 39: unsigned long bsi, size_range;
! 40:
! 41: tests_start ();
! 42: rands = RANDS;
! 43:
! 44: mp_trace_base = -16;
! 45:
! 46: mpz_init (bs);
! 47:
! 48: if (argc == 2)
! 49: reps = atoi (argv[1]);
! 50:
! 51: mpz_init (op1);
! 52: mpz_init (op2);
! 53: mpz_init (prod);
! 54: mpz_init (quot);
! 55:
! 56: for (i = 0; i < reps; i++)
! 57: {
! 58: mpz_urandomb (bs, rands, 32);
! 59: size_range = mpz_get_ui (bs) % 10 + 2; /* 0..2047 bit operands */
! 60:
! 61: mpz_urandomb (bs, rands, size_range);
! 62: size = mpz_get_ui (bs);
! 63: mpz_rrandomb (op1, rands, size);
! 64:
! 65: do
! 66: {
! 67: mpz_urandomb (bs, rands, size_range);
! 68: size = mpz_get_ui (bs);
! 69: mpz_rrandomb (op2, rands, size);
! 70: }
! 71: while (mpz_sgn (op2) == 0);
! 72:
! 73: mpz_urandomb (bs, rands, 2);
! 74: bsi = mpz_get_ui (bs);
! 75: if ((bsi & 1) != 0)
! 76: mpz_neg (op1, op1);
! 77: if ((bsi & 2) != 0)
! 78: mpz_neg (op2, op2);
! 79:
! 80: mpz_mul (prod, op1, op2);
! 81:
! 82: mpz_divexact (quot, prod, op2);
! 83: MPZ_CHECK_FORMAT (quot);
! 84:
! 85: if (mpz_cmp (quot, op1) != 0)
! 86: {
! 87: printf ("Wrong results:\n");
! 88: mpz_trace (" got ", quot);
! 89: mpz_trace (" want ", op1);
! 90: mpz_trace (" dividend", prod);
! 91: mpz_trace (" divisor ", op2);
! 92: abort ();
! 93: }
! 94: }
! 95:
! 96: mpz_clear (bs);
! 97: mpz_clear (op1);
! 98: mpz_clear (op2);
! 99: mpz_clear (prod);
! 100: mpz_clear (quot);
! 101:
! 102: tests_end ();
! 103: exit (0);
! 104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>