Upload Tizen:Base source
[external/gmp.git] / tests / mpz / t-mul_i.c
1 /* Test mpz_mul_ui and mpz_mul_si.
2
3 Copyright 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 3 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.  If not, see http://www.gnu.org/licenses/.  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include "gmp.h"
24 #include "gmp-impl.h"
25 #include "tests.h"
26
27
28 mpz_t got, want, x;
29
30 void
31 compare_si (long y)
32 {
33   if (mpz_cmp (got, want) != 0)
34     {
35       printf    ("mpz_mul_si wrong\n");
36       mpz_trace ("  x", x);
37       printf    ("  y=%ld (0x%lX)\n", y, y);
38       mpz_trace ("  got ", got);
39       mpz_trace ("  want", want);
40       abort ();
41     }
42 }
43
44 void
45 compare_ui (unsigned long y)
46 {
47   if (mpz_cmp (got, want) != 0)
48     {
49       printf    ("mpz_mul_ui wrong\n");
50       mpz_trace ("  x", x);
51       printf    ("  y=%lu (0x%lX)\n", y, y);
52       mpz_trace ("  got ", got);
53       mpz_trace ("  want", want);
54       abort ();
55     }
56 }
57
58 void
59 check_samples (void)
60 {
61   {
62     long  y;
63
64     mpz_set_ui (x, 1L);
65     y = 0;
66     mpz_mul_si (got, x, y);
67     mpz_set_si (want, y);
68     compare_si (y);
69
70     mpz_set_ui (x, 1L);
71     y = 1;
72     mpz_mul_si (got, x, y);
73     mpz_set_si (want, y);
74     compare_si (y);
75
76     mpz_set_ui (x, 1L);
77     y = -1;
78     mpz_mul_si (got, x, y);
79     mpz_set_si (want, y);
80     compare_si (y);
81
82     mpz_set_ui (x, 1L);
83     y = LONG_MIN;
84     mpz_mul_si (got, x, y);
85     mpz_set_si (want, y);
86     compare_si (y);
87
88     mpz_set_ui (x, 1L);
89     y = LONG_MAX;
90     mpz_mul_si (got, x, y);
91     mpz_set_si (want, y);
92     compare_si (y);
93   }
94
95   {
96     unsigned long y;
97
98     mpz_set_ui (x, 1L);
99     y = 0;
100     mpz_mul_ui (got, x, y);
101     mpz_set_ui (want, y);
102     compare_ui (y);
103
104     mpz_set_ui (x, 1L);
105     y = 1;
106     mpz_mul_ui (got, x, y);
107     mpz_set_ui (want, y);
108     compare_ui (y);
109
110     mpz_set_ui (x, 1L);
111     y = ULONG_MAX;
112     mpz_mul_ui (got, x, y);
113     mpz_set_ui (want, y);
114     compare_ui (y);
115   }
116 }
117
118 int
119 main (int argc, char **argv)
120 {
121   tests_start ();
122
123   mpz_init (x);
124   mpz_init (got);
125   mpz_init (want);
126
127   check_samples ();
128
129   mpz_clear (x);
130   mpz_clear (got);
131   mpz_clear (want);
132
133   tests_end ();
134   exit (0);
135 }