diff options
author | Kevin Newton <[email protected]> | 2024-02-23 12:39:11 -0500 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-02-23 13:25:31 -0500 |
commit | 02b531a813a6d68eea8b93aaf33fac57837ad90c (patch) | |
tree | dfd7b40e1d5e7d74a7fb483a1bf0acfd043816a4 /prism/util/pm_integer.c | |
parent | b9202788f8a1098994082aee5bcb9f6d0cc73eb0 (diff) |
[ruby/prism] Factor in sign to integer comparison
https://github.com/ruby/prism/commit/377666a5df
Diffstat (limited to 'prism/util/pm_integer.c')
-rw-r--r-- | prism/util/pm_integer.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/prism/util/pm_integer.c b/prism/util/pm_integer.c index ff683d3501..e39108a05b 100644 --- a/prism/util/pm_integer.c +++ b/prism/util/pm_integer.c @@ -159,16 +159,19 @@ pm_integer_memsize(const pm_integer_t *integer) { */ int pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right) { - if (left->length < right->length) return -1; - if (left->length > right->length) return 1; + if (left->negative != right->negative) return left->negative ? -1 : 1; + int negative = left->negative ? -1 : 1; + + if (left->length < right->length) return -1 * negative; + if (left->length > right->length) return 1 * negative; for ( const pm_integer_word_t *left_word = &left->head, *right_word = &right->head; left_word != NULL && right_word != NULL; left_word = left_word->next, right_word = right_word->next ) { - if (left_word->value < right_word->value) return -1; - if (left_word->value > right_word->value) return 1; + if (left_word->value < right_word->value) return -1 * negative; + if (left_word->value > right_word->value) return 1 * negative; } return 0; |