bn_mp_cmp_d.c

Go to the documentation of this file.
00001 #include <tommath.h>
00002 #ifdef BN_MP_CMP_D_C
00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis
00004  *
00005  * LibTomMath is a library that provides multiple-precision
00006  * integer arithmetic as well as number theoretic functionality.
00007  *
00008  * The library was designed directly after the MPI library by
00009  * Michael Fromberger but has been written from scratch with
00010  * additional optimizations in place.
00011  *
00012  * The library is free for all purposes without any express
00013  * guarantee it works.
00014  *
00015  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
00016  */
00017 
00018 /* compare a digit */
00019 int mp_cmp_d(mp_int * a, mp_digit b)
00020 {
00021   /* compare based on sign */
00022   if (a->sign == MP_NEG) {
00023     return MP_LT;
00024   }
00025 
00026   /* compare based on magnitude */
00027   if (a->used > 1) {
00028     return MP_GT;
00029   }
00030 
00031   /* compare the only digit of a to b */
00032   if (a->dp[0] > b) {
00033     return MP_GT;
00034   } else if (a->dp[0] < b) {
00035     return MP_LT;
00036   } else {
00037     return MP_EQ;
00038   }
00039 }
00040 #endif
00041 
00042 /* $Source: /cvsroot/tcl/libtommath/bn_mp_cmp_d.c,v $ */
00043 /* $Revision: 1.1.1.3 $ */
00044 /* $Date: 2006/12/01 00:08:11 $ */



Generated on Wed Mar 12 12:18:24 2008 by  doxygen 1.5.1