Skip to content

fix: support bigint operands in arithmetic and comparisons - #140

Open
zhangga wants to merge 1 commit into
dcodeIO:mainfrom
zhangga:fix/bigint-operands
Open

zhangga wants to merge 1 commit into
dcodeIO:mainfrom
zhangga:fix/bigint-operands

Conversation

@zhangga

@zhangga zhangga commented Oct 29, 2026

Copy link
Copy Markdown

Native bigint operands are accepted by the public typings, but arithmetic, comparison and bitwise methods call the internal fromValue, which does not handle bigint. These inputs are converted to zero-valued low/high words.

Reproductions on current main / long@5.3.2:

Long.ONE.add(2n).toString(); // "1", expected "3"
Long.ONE.eq(1n); // false, expected true
Long.fromInt(4).div(2n); // throws "division by zero", expected 2

Move bigint dispatch into the shared internal fromValue and remove the redundant public wrapper. Long.fromValue(bigint) remains supported, and methods now use the same conversion. The bigint check remains first in the dispatch path.

Add regression coverage against native BigInt for arithmetic, bitwise operations, comparisons, division/remainder by zero and conversion of values outside 64 bits.

Validation (Node 22.13.0):

  • New regression fails before the fix.
  • npm run build
  • npm test (unit tests, Closure library tests and all four TypeScript configurations)
  • npm run lint
  • Full unit/Closure suite also run against the generated UMD implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant