bn_mp_cmp_d.c 580 B

12345678910111213141516171819202122232425262728
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_CMP_D_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* compare a digit */
  6. mp_ord mp_cmp_d(const mp_int *a, mp_digit b)
  7. {
  8. /* compare based on sign */
  9. if (a->sign == MP_NEG) {
  10. return MP_LT;
  11. }
  12. /* compare based on magnitude */
  13. if (a->used > 1) {
  14. return MP_GT;
  15. }
  16. /* compare the only digit of a to b */
  17. if (a->dp[0] > b) {
  18. return MP_GT;
  19. } else if (a->dp[0] < b) {
  20. return MP_LT;
  21. } else {
  22. return MP_EQ;
  23. }
  24. }
  25. #endif