Skip to content

Commit

Permalink
fix(runtime): Handle bigint mul/div within Number correctly (#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer authored Nov 11, 2022
1 parent d705849 commit 0fe8aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/test/stdlib/number.test.gr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ assert Number.isNaN(Number.sub(Number.nan, Number.nan))
}
// mul
assert Number.mul(5, 5) == 25
assert Number.mul(9223372036854775809, 5) == 46116860184273879045
assert Number.mul(9223372036854775809, 9223372036854775809) ==
85070591730234615884290395931651604481
assert Number.mul(Number.infinity, 10) == Number.infinity
assert Number.mul(Number.infinity, Number.infinity) == Number.infinity
assert Number.isNaN(Number.mul(Number.infinity, Number.nan))
Expand All @@ -72,6 +75,8 @@ assert Number.isNaN(Number.mul(Number.nan, Number.nan))
}
// div
assert Number.div(25, 5) == 5
assert Number.div(9223372036854775809, 9) == 1024819115206086201
assert Number.div(9223372036854775809, 9223372036854775809) == 1
assert Number.div(Number.infinity, 10) == Number.infinity
assert Number.isNaN(Number.div(Number.infinity, Number.infinity))
assert Number.isNaN(Number.div(Number.infinity, Number.nan))
Expand Down
7 changes: 7 additions & 0 deletions stdlib/runtime/numbers.gr
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,13 @@ let numberTimesDivideBigIntHelp = (x, y, isDivide) => {
Memory.decRef(yBig)
ret
},
t when WasmI32.eq(t, Tags._GRAIN_BIGINT_BOXED_NUM_TAG) => {
if (isDivide) {
reducedBigInteger(BI.div(x, y))
} else {
reducedBigInteger(BI.mul(x, y))
}
},
t when WasmI32.eq(t, Tags._GRAIN_RATIONAL_BOXED_NUM_TAG) => {
let yNumerator = boxedRationalNumerator(y)
let yDenominator = boxedRationalDenominator(y)
Expand Down

0 comments on commit 0fe8aa6

Please sign in to comment.