bn_mp_cmp_d.c 1.0 KB

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