raw
smg_comms_c_wrappers    1 /* mpi-cmp.c  -  MPI functions
smg_comms_c_wrappers 2 * Modified by No Such Labs. (C) 2015. See README.
smg_comms_c_wrappers 3 *
smg_comms_c_wrappers 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
smg_comms_c_wrappers 5 * SHA256(gnupg-1.4.10.tar.gz):
smg_comms_c_wrappers 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
smg_comms_c_wrappers 7 * (C) 1994-2005 Free Software Foundation, Inc.
smg_comms_c_wrappers 8 *
smg_comms_c_wrappers 9 * This program is free software: you can redistribute it and/or modify
smg_comms_c_wrappers 10 * it under the terms of the GNU General Public License as published by
smg_comms_c_wrappers 11 * the Free Software Foundation, either version 3 of the License, or
smg_comms_c_wrappers 12 * (at your option) any later version.
smg_comms_c_wrappers 13 *
smg_comms_c_wrappers 14 * This program is distributed in the hope that it will be useful,
smg_comms_c_wrappers 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
smg_comms_c_wrappers 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
smg_comms_c_wrappers 17 * GNU General Public License for more details.
smg_comms_c_wrappers 18 *
smg_comms_c_wrappers 19 * You should have received a copy of the GNU General Public License
smg_comms_c_wrappers 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
smg_comms_c_wrappers 21 */
smg_comms_c_wrappers 22
smg_comms_c_wrappers 23 #include <stdio.h>
smg_comms_c_wrappers 24 #include <stdlib.h>
smg_comms_c_wrappers 25
smg_comms_c_wrappers 26 #include "knobs.h"
smg_comms_c_wrappers 27 #include "mpi-internal.h"
smg_comms_c_wrappers 28
smg_comms_c_wrappers 29 int
smg_comms_c_wrappers 30 mpi_cmp_ui( MPI u, unsigned long v )
smg_comms_c_wrappers 31 {
smg_comms_c_wrappers 32 mpi_limb_t limb = v;
smg_comms_c_wrappers 33
smg_comms_c_wrappers 34 mpi_normalize( u );
smg_comms_c_wrappers 35 if( !u->nlimbs && !limb )
smg_comms_c_wrappers 36 return 0;
smg_comms_c_wrappers 37 if( u->sign )
smg_comms_c_wrappers 38 return -1;
smg_comms_c_wrappers 39 if( u->nlimbs > 1 )
smg_comms_c_wrappers 40 return 1;
smg_comms_c_wrappers 41
smg_comms_c_wrappers 42 if( u->d[0] == limb )
smg_comms_c_wrappers 43 return 0;
smg_comms_c_wrappers 44 else if( u->d[0] > limb )
smg_comms_c_wrappers 45 return 1;
smg_comms_c_wrappers 46 else
smg_comms_c_wrappers 47 return -1;
smg_comms_c_wrappers 48 }
smg_comms_c_wrappers 49
smg_comms_c_wrappers 50 int
smg_comms_c_wrappers 51 mpi_cmp( MPI u, MPI v )
smg_comms_c_wrappers 52 {
smg_comms_c_wrappers 53 mpi_size_t usize, vsize;
smg_comms_c_wrappers 54 int cmp;
smg_comms_c_wrappers 55
smg_comms_c_wrappers 56 mpi_normalize( u );
smg_comms_c_wrappers 57 mpi_normalize( v );
smg_comms_c_wrappers 58 usize = u->nlimbs;
smg_comms_c_wrappers 59 vsize = v->nlimbs;
smg_comms_c_wrappers 60 if( !u->sign && v->sign )
smg_comms_c_wrappers 61 return 1;
smg_comms_c_wrappers 62 if( u->sign && !v->sign )
smg_comms_c_wrappers 63 return -1;
smg_comms_c_wrappers 64 if( usize != vsize && !u->sign && !v->sign )
smg_comms_c_wrappers 65 return usize - vsize;
smg_comms_c_wrappers 66 if( usize != vsize && u->sign && v->sign )
smg_comms_c_wrappers 67 return vsize + usize;
smg_comms_c_wrappers 68 if( !usize )
smg_comms_c_wrappers 69 return 0;
smg_comms_c_wrappers 70 if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) )
smg_comms_c_wrappers 71 return 0;
smg_comms_c_wrappers 72 if( (cmp < 0?1:0) == (u->sign?1:0))
smg_comms_c_wrappers 73 return 1;
smg_comms_c_wrappers 74 return -1;
smg_comms_c_wrappers 75 }
smg_comms_c_wrappers 76
smg_comms_c_wrappers 77