source: trunk/third/gmp/tests/mpz/t-mul_i.c @ 18191

Revision 18191, 2.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test mpz_mul_ui and mpz_mul_si.
2
3Copyright 2001, 2002 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 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
30mpz_t got, want, x;
31
32void
33compare_si (long y)
34{
35  if (mpz_cmp (got, want) != 0)
36    {
37      printf    ("mpz_mul_si wrong\n");
38      mpz_trace ("  x", x);
39      printf    ("  y=%ld (0x%lX)\n", y, y);
40      mpz_trace ("  got ", got);
41      mpz_trace ("  want", want);
42      abort ();
43    }
44}
45
46void
47compare_ui (unsigned long y)
48{
49  if (mpz_cmp (got, want) != 0)
50    {
51      printf    ("mpz_mul_ui wrong\n");
52      mpz_trace ("  x", x);
53      printf    ("  y=%lu (0x%lX)\n", y, y);
54      mpz_trace ("  got ", got);
55      mpz_trace ("  want", want);
56      abort ();
57    }
58}
59
60void
61check_samples (void)
62{
63  {
64    long  y;
65
66    mpz_set_ui (x, 1L);
67    y = 0;
68    mpz_mul_si (got, x, y);
69    mpz_set_si (want, y);
70    compare_si (y);
71
72    mpz_set_ui (x, 1L);
73    y = 1;
74    mpz_mul_si (got, x, y);
75    mpz_set_si (want, y);
76    compare_si (y);
77
78    mpz_set_ui (x, 1L);
79    y = -1;
80    mpz_mul_si (got, x, y);
81    mpz_set_si (want, y);
82    compare_si (y);
83
84    mpz_set_ui (x, 1L);
85    y = LONG_MIN;
86    mpz_mul_si (got, x, y);
87    mpz_set_si (want, y);
88    compare_si (y);
89
90    mpz_set_ui (x, 1L);
91    y = LONG_MAX;
92    mpz_mul_si (got, x, y);
93    mpz_set_si (want, y);
94    compare_si (y);
95  }
96
97  {
98    unsigned long y;
99 
100    mpz_set_ui (x, 1L);
101    y = 0;
102    mpz_mul_ui (got, x, y);
103    mpz_set_ui (want, y);
104    compare_ui (y);
105
106    mpz_set_ui (x, 1L);
107    y = 1;
108    mpz_mul_ui (got, x, y);
109    mpz_set_ui (want, y);
110    compare_ui (y);
111
112    mpz_set_ui (x, 1L);
113    y = ULONG_MAX;
114    mpz_mul_ui (got, x, y);
115    mpz_set_ui (want, y);
116    compare_ui (y);
117  }
118}
119
120int
121main (int argc, char **argv)
122{
123  tests_start ();
124
125  mpz_init (x);
126  mpz_init (got);
127  mpz_init (want);
128
129  check_samples ();
130
131  mpz_clear (x);
132  mpz_clear (got);
133  mpz_clear (want);
134
135  tests_end ();
136  exit (0);
137}
Note: See TracBrowser for help on using the repository browser.