~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to gmp/mpz/tests/dive.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test mpz_mul, mpz_divexact.
 
2
 
 
3
Copyright (C) 1996 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
#include <string.h>
 
25
#include "gmp.h"
 
26
#include "gmp-impl.h"
 
27
#include "urandom.h"
 
28
 
 
29
size_t
 
30
#if defined(__STDC__)
 
31
  mpz_out_str (FILE *stream, int base, mpz_srcptr x);
 
32
#else
 
33
  mpz_out_str (stream, base, x);
 
34
#endif
 
35
 
 
36
int dump_abort (mpz_t op1, mpz_t op2);
 
37
 
 
38
void debug_mp ();
 
39
 
 
40
#ifndef SIZE
 
41
#define SIZE 32
 
42
#endif
 
43
 
 
44
main (argc, argv)
 
45
     int argc;
 
46
     char **argv;
 
47
{
 
48
  mpz_t op1, op2;
 
49
  mpz_t prod, quot;
 
50
  mp_size_t size;
 
51
  int i;
 
52
  int reps = 100000;
 
53
 
 
54
  if (argc == 2)
 
55
     reps = atoi (argv[1]);
 
56
 
 
57
  mpz_init (op1);
 
58
  mpz_init (op2);
 
59
  mpz_init (prod);
 
60
  mpz_init (quot);
 
61
 
 
62
  for (i = 0; i < reps; i++)
 
63
    {
 
64
      size = urandom () % SIZE - SIZE/2;
 
65
      mpz_random2 (op1, size);
 
66
 
 
67
      do
 
68
        {
 
69
          size = urandom () % SIZE - SIZE/2;
 
70
          mpz_random2 (op2, size);
 
71
        }
 
72
      while (mpz_cmp_ui (op2, 0) == 0);
 
73
 
 
74
      mpz_mul (prod, op1, op2);
 
75
 
 
76
      mpz_divexact (quot, prod, op2);
 
77
      if (mpz_cmp (quot, op1) != 0)
 
78
        dump_abort (quot, op1);
 
79
    }
 
80
 
 
81
  exit (0);
 
82
}
 
83
 
 
84
dump_abort (op1, op2)
 
85
     mpz_t op1, op2;
 
86
{
 
87
  fprintf (stderr, "ERROR\n");
 
88
  fprintf (stderr, "ref = "); debug_mp (op1, -16);
 
89
  fprintf (stderr, "wrong = "); debug_mp (op2, -16);
 
90
  abort();
 
91
}
 
92
 
 
93
void
 
94
debug_mp (x, base)
 
95
     mpz_t x;
 
96
{
 
97
  mpz_out_str (stderr, base, x); fputc ('\n', stderr);
 
98
}