remove empty dir
[ghc-hetmet.git] / ghc / rts / gmp / mpz / cmp.c
1 /* mpz_cmp(u,v) -- Compare U, V.  Return postive, zero, or negative
2    based on if U > V, U == V, or U < V.
3
4 Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
5
6 This file is part of the GNU MP Library.
7
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or (at your
11 option) any later version.
12
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
22
23 #ifdef BERKELEY_MP
24 #include "mp.h"
25 #endif
26 #include "gmp.h"
27 #include "gmp-impl.h"
28
29 #ifndef BERKELEY_MP
30 int
31 #if __STDC__
32 mpz_cmp (mpz_srcptr u, mpz_srcptr v)
33 #else
34 mpz_cmp (u, v)
35      mpz_srcptr u;
36      mpz_srcptr v;
37 #endif
38 #else /* BERKELEY_MP */
39 int
40 #if __STDC__
41 mcmp (mpz_srcptr u, mpz_srcptr v)
42 #else
43 mcmp (u, v)
44      mpz_srcptr u;
45      mpz_srcptr v;
46 #endif
47 #endif /* BERKELEY_MP */
48 {
49   mp_size_t usize = u->_mp_size;
50   mp_size_t vsize = v->_mp_size;
51   mp_size_t size;
52   mp_srcptr up, vp;
53   int cmp;
54
55   if (usize != vsize)
56     return usize - vsize;
57
58   if (usize == 0)
59     return 0;
60
61   size = ABS (usize);
62
63   up = u->_mp_d;
64   vp = v->_mp_d;
65
66   cmp = mpn_cmp (up, vp, size);
67
68   if (cmp == 0)
69     return 0;
70
71   if ((cmp < 0) == (usize < 0))
72     return 1;
73   else
74     return -1;
75 }