1 /* $NetBSD: bn_mp_cmp_d.c,v 1.1.1.1 2011/04/13 18:14:54 elric Exp $ */ 2 3 #include <tommath.h> 4 #ifdef BN_MP_CMP_D_C 5 /* LibTomMath, multiple-precision integer library -- Tom St Denis 6 * 7 * LibTomMath is a library that provides multiple-precision 8 * integer arithmetic as well as number theoretic functionality. 9 * 10 * The library was designed directly after the MPI library by 11 * Michael Fromberger but has been written from scratch with 12 * additional optimizations in place. 13 * 14 * The library is free for all purposes without any express 15 * guarantee it works. 16 * 17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 18 */ 19 20 /* compare a digit */ 21 int mp_cmp_d(mp_int * a, mp_digit b) 22 { 23 /* compare based on sign */ 24 if (a->sign == MP_NEG) { 25 return MP_LT; 26 } 27 28 /* compare based on magnitude */ 29 if (a->used > 1) { 30 return MP_GT; 31 } 32 33 /* compare the only digit of a to b */ 34 if (a->dp[0] > b) { 35 return MP_GT; 36 } else if (a->dp[0] < b) { 37 return MP_LT; 38 } else { 39 return MP_EQ; 40 } 41 } 42 #endif 43 44 /* Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v */ 45 /* Revision: 1.4 */ 46 /* Date: 2006/12/28 01:25:13 */ 47