1 /* mpq_equal(u,v) -- Compare U, V. Return non-zero if they are equal, zero
4 Copyright 1996, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any
21 or both in parallel, as here.
23 The GNU MP Library is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 You should have received copies of the GNU General Public License and the
29 GNU Lesser General Public License along with the GNU MP Library. If not,
30 see https://www.gnu.org/licenses/. */
36 mpq_equal (mpq_srcptr op1
, mpq_srcptr op2
) __GMP_NOTHROW
38 mp_size_t num1_size
, num2_size
, den1_size
, den2_size
, i
;
39 mp_srcptr num1_ptr
, num2_ptr
, den1_ptr
, den2_ptr
;
41 /* need fully canonical for correct results */
42 ASSERT_MPQ_CANONICAL (op1
);
43 ASSERT_MPQ_CANONICAL (op2
);
45 num1_size
= SIZ(NUM(op1
));
46 num2_size
= SIZ(NUM(op2
));
47 if (num1_size
!= num2_size
)
50 num1_ptr
= PTR(NUM(op1
));
51 num2_ptr
= PTR(NUM(op2
));
52 num1_size
= ABS (num1_size
);
53 for (i
= 0; i
< num1_size
; i
++)
54 if (num1_ptr
[i
] != num2_ptr
[i
])
57 den1_size
= SIZ(DEN(op1
));
58 den2_size
= SIZ(DEN(op2
));
59 if (den1_size
!= den2_size
)
62 den1_ptr
= PTR(DEN(op1
));
63 den2_ptr
= PTR(DEN(op2
));
64 for (i
= 0; i
< den1_size
; i
++)
65 if (den1_ptr
[i
] != den2_ptr
[i
])