bn_mp_cmp.c 597 B

1234567891011121314151617181920212223242526
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_CMP_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* compare two ints (signed)*/
  6. mp_ord mp_cmp(const mp_int *a, const mp_int *b)
  7. {
  8. /* compare based on sign */
  9. if (a->sign != b->sign) {
  10. if (a->sign == MP_NEG) {
  11. return MP_LT;
  12. } else {
  13. return MP_GT;
  14. }
  15. }
  16. /* compare digits */
  17. if (a->sign == MP_NEG) {
  18. /* if negative compare opposite direction */
  19. return mp_cmp_mag(b, a);
  20. } else {
  21. return mp_cmp_mag(a, b);
  22. }
  23. }
  24. #endif