1 /* Test mpz_cmp and mpz_cmpabs.
3 Copyright 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 3 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. If not, see http://www.gnu.org/licenses/. */
27 /* Nothing sophisticated here, just exercise some combinations of sizes and
32 check_one (mpz_ptr x, mpz_ptr y, int want_cmp, int want_cmpabs)
37 if (( got < 0) != (want_cmp < 0)
38 || (got == 0) != (want_cmp == 0)
39 || (got > 0) != (want_cmp > 0))
41 printf ("mpz_cmp got %d want %d\n", got, want_cmp);
47 got = mpz_cmpabs (x, y);
48 if (( got < 0) != (want_cmpabs < 0)
49 || (got == 0) != (want_cmpabs == 0)
50 || (got > 0) != (want_cmpabs > 0))
52 printf ("mpz_cmpabs got %d want %d\n", got, want_cmpabs);
61 check_all (mpz_ptr x, mpz_ptr y, int want_cmp, int want_cmpabs)
63 check_one (x, y, want_cmp, want_cmpabs);
64 check_one (y, x, -want_cmp, -want_cmpabs);
70 check_one (x, y, want_cmp, want_cmpabs);
71 check_one (y, x, -want_cmp, -want_cmpabs);
75 #define SET1(z,size, n) \
76 SIZ(z) = size; PTR(z)[0] = n
78 #define SET2(z,size, n1,n0) \
79 SIZ(z) = size; PTR(z)[1] = n1; PTR(z)[0] = n0
81 #define SET4(z,size, n3,n2,n1,n0) \
82 SIZ(z) = size; PTR(z)[3] = n3; PTR(z)[2] = n2; PTR(z)[1] = n1; PTR(z)[0] = n0
92 mpz_realloc (x, (mp_size_t) 20);
93 mpz_realloc (y, (mp_size_t) 20);
95 /* 0 cmp 0, junk in low limbs */
98 check_all (x, y, 0, 0);
104 check_all (x, y, 1, 1);
109 check_all (x, y, 1, 1);
115 check_all (x, y, 0, 0);
120 check_all (x, y, -1, 0);
126 check_all (x, y, -1, -1);
131 check_all (x, y, -1, -1);
136 check_all (x, y, 1, -1);
142 check_all (x, y, 0, 0);
147 check_all (x, y, -1, 0);
153 check_all (x, y, 1, 1);
156 /* 4:3:2:1 cmp 2:1 */
159 check_all (x, y, 1, 1);
161 /* -4:3:2:1 cmp 2:1 */
162 SET4 (x,-4, 4,3,2,1);
164 check_all (x, y, -1, 1);