1*181254a7Smrg /* mpn_cmp -- Compare two low-level natural-number integers.
2*181254a7Smrg
3*181254a7Smrg Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
4*181254a7Smrg
5*181254a7Smrg This file is part of the GNU MP Library.
6*181254a7Smrg
7*181254a7Smrg The GNU MP Library is free software; you can redistribute it and/or modify
8*181254a7Smrg it under the terms of the GNU Lesser General Public License as published by
9*181254a7Smrg the Free Software Foundation; either version 2.1 of the License, or (at your
10*181254a7Smrg option) any later version.
11*181254a7Smrg
12*181254a7Smrg The GNU MP Library is distributed in the hope that it will be useful, but
13*181254a7Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14*181254a7Smrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15*181254a7Smrg License for more details.
16*181254a7Smrg
17*181254a7Smrg You should have received a copy of the GNU Lesser General Public License
18*181254a7Smrg along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19*181254a7Smrg the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20*181254a7Smrg MA 02111-1307, USA. */
21*181254a7Smrg
22*181254a7Smrg #include <config.h>
23*181254a7Smrg #include "gmp-impl.h"
24*181254a7Smrg
25*181254a7Smrg /* Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
26*181254a7Smrg There are no restrictions on the relative sizes of
27*181254a7Smrg the two arguments.
28*181254a7Smrg Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2. */
29*181254a7Smrg
30*181254a7Smrg int
31*181254a7Smrg #if __STDC__
mpn_cmp(mp_srcptr op1_ptr,mp_srcptr op2_ptr,mp_size_t size)32*181254a7Smrg mpn_cmp (mp_srcptr op1_ptr, mp_srcptr op2_ptr, mp_size_t size)
33*181254a7Smrg #else
34*181254a7Smrg mpn_cmp (op1_ptr, op2_ptr, size)
35*181254a7Smrg mp_srcptr op1_ptr;
36*181254a7Smrg mp_srcptr op2_ptr;
37*181254a7Smrg mp_size_t size;
38*181254a7Smrg #endif
39*181254a7Smrg {
40*181254a7Smrg mp_size_t i;
41*181254a7Smrg mp_limb_t op1_word, op2_word;
42*181254a7Smrg
43*181254a7Smrg for (i = size - 1; i >= 0; i--)
44*181254a7Smrg {
45*181254a7Smrg op1_word = op1_ptr[i];
46*181254a7Smrg op2_word = op2_ptr[i];
47*181254a7Smrg if (op1_word != op2_word)
48*181254a7Smrg goto diff;
49*181254a7Smrg }
50*181254a7Smrg return 0;
51*181254a7Smrg diff:
52*181254a7Smrg /* This can *not* be simplified to
53*181254a7Smrg op2_word - op2_word
54*181254a7Smrg since that expression might give signed overflow. */
55*181254a7Smrg return (op1_word > op2_word) ? 1 : -1;
56*181254a7Smrg }
57