Home | History | Annotate | Line # | Download | only in mpq
      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, 2018 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-impl.h"
     33 
     34 int
     35 mpq_equal (mpq_srcptr op1, mpq_srcptr op2) __GMP_NOTHROW
     36 {
     37   mp_size_t  num1_size, num2_size, den1_size, den2_size, i;
     38   mp_srcptr  num1_ptr,  num2_ptr,  den1_ptr,  den2_ptr;
     39 
     40   /* need fully canonical for correct results */
     41   ASSERT_MPQ_CANONICAL (op1);
     42   ASSERT_MPQ_CANONICAL (op2);
     43 
     44   num1_size = SIZ(NUM(op1));
     45   num2_size = SIZ(NUM(op2));
     46   if (num1_size != num2_size)
     47     return 0;
     48 
     49   den1_size = SIZ(DEN(op1));
     50   den2_size = SIZ(DEN(op2));
     51   if (den1_size != den2_size)
     52     return 0;
     53 
     54   num1_ptr = PTR(NUM(op1));
     55   num2_ptr = PTR(NUM(op2));
     56   num1_size = ABS (num1_size);
     57   for (i = 0; i < num1_size; i++)
     58     if (num1_ptr[i] != num2_ptr[i])
     59       return 0;
     60 
     61   den1_ptr = PTR(DEN(op1));
     62   den2_ptr = PTR(DEN(op2));
     63   for (i = 0; i < den1_size; i++)
     64     if (den1_ptr[i] != den2_ptr[i])
     65       return 0;
     66 
     67   return 1;
     68 }
     69