LibJS: Check both the quotient and remainder for rounding negativity

Our BigInt implementation can store the negativity of the division
result in either the quotient or the remainder. This is exposed by an
upcoming prototype, which will reach this division with:

    -432000000000000 / 86400000000000000000000

Which has the BigInt division result:

    quotient = 0
    remainder = -432000000000000

(Our old Temporal implementation also had this bug).
This commit is contained in:
Timothy Flynn 2024-11-22 14:35:35 -05:00 committed by Andreas Kling
parent b319d45566
commit abc6b679c3
Notes: github-actions[bot] 2024-11-23 13:47:52 +00:00

View file

@ -788,7 +788,7 @@ Crypto::SignedBigInteger round_number_to_increment(Crypto::SignedBigInteger cons
Sign is_negative;
// 2. If quotient < 0, then
if (division_result.quotient.is_negative()) {
if (division_result.quotient.is_negative() || division_result.remainder.is_negative()) {
// a. Let isNegative be NEGATIVE.
is_negative = Sign::Negative;