github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpq/equal.c (about) 1 /* mpq_equal(u,v) -- Compare U, V. Return non-zero if they are equal, zero 2 if they are non-equal. 3 4 Copyright 1996, 2001, 2002 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 either: 10 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. 14 15 or 16 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 19 later version. 20 21 or both in parallel, as here. 22 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 26 for more details. 27 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/. */ 31 32 #include "gmp.h" 33 #include "gmp-impl.h" 34 35 int 36 mpq_equal (mpq_srcptr op1, mpq_srcptr op2) __GMP_NOTHROW 37 { 38 mp_size_t num1_size, num2_size, den1_size, den2_size, i; 39 mp_srcptr num1_ptr, num2_ptr, den1_ptr, den2_ptr; 40 41 /* need fully canonical for correct results */ 42 ASSERT_MPQ_CANONICAL (op1); 43 ASSERT_MPQ_CANONICAL (op2); 44 45 num1_size = SIZ(NUM(op1)); 46 num2_size = SIZ(NUM(op2)); 47 if (num1_size != num2_size) 48 return 0; 49 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]) 55 return 0; 56 57 den1_size = SIZ(DEN(op1)); 58 den2_size = SIZ(DEN(op2)); 59 if (den1_size != den2_size) 60 return 0; 61 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]) 66 return 0; 67 68 return 1; 69 }