[ruby/prism] Factor in sign to integer comparison
https://github.com/ruby/prism/commit/377666a5df
This commit is contained in:
parent
b9202788f8
commit
02b531a813
@ -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;
|
||||
|
@ -13,6 +13,10 @@ module Prism
|
||||
assert_warning((2**32).to_s(10), "0x#{(2**32).to_s(16)}")
|
||||
assert_warning((2**64).to_s(10), "0x#{(2**64).to_s(16)}")
|
||||
|
||||
refute_warning("1", "-1")
|
||||
refute_warning((2**32).to_s(10), "-0x#{(2**32).to_s(16)}")
|
||||
refute_warning((2**64).to_s(10), "-0x#{(2**64).to_s(16)}")
|
||||
|
||||
assert_warning("__LINE__", "2")
|
||||
assert_warning("3", "__LINE__")
|
||||
|
||||
@ -33,6 +37,7 @@ module Prism
|
||||
assert_warning("\"#{__FILE__}\"", "__FILE__")
|
||||
|
||||
assert_warning("/foo/")
|
||||
|
||||
refute_warning("/foo/", "/foo/i")
|
||||
|
||||
assert_warning(":foo")
|
||||
|
Loading…
x
Reference in New Issue
Block a user