Skip to content

bigint: literals are bigint, 64-bit /, % and shifts, wrapper calls convert - #727

Merged
ASDAlexander77 merged 1 commit into
mainfrom
bigint-cluster
Oct 29, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
bigint-cluster

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Makes bigint usable: three compile failures, two silently wrong results, and the standard conversion calls.

Literals are bigint. A bigint literal was typed as a plain i64, so:

  • x ?? 7n on an optional bigint merged into bigint | i64 and failed in LLVM (an i64 compared with a null pointer);
  • 5n given for a bigint | string parameter was an invalid cast.

The literal is now a bigint. ?? also treats a bigint as never null, as it does a number.

Out-of-range literals are an error. A bigint is a 64-bit signed integer here, and 12345678901234567890n silently printed -6101065172474983726. It's now a compile error.

/, %, shifts and bitwise operators stay 64-bit integers. Previously:

  • 10n / 3n was 3.33333, computed through a number;
  • 1n << 40n was 256, shifted by 40 mod 32 through an i32.

Both now give the bigint results (3n, 1099511627776n). This includes the compound forms (/=, <<=).

Number(x), BigInt(x), String(x) and Boolean(x) without new convert to the primitive, as in JavaScript. They used to make the wrapper object, so BigInt(42) + 1n and Number(x) + 0.5 failed as invalid casts. new Number(x) still makes the object.

Tests:

  • 00bigint_ops runs under gc, rc and none;
  • diagnostic-location/bigint_literal_out_of_range checks the error;
  • the conversions use the DefaultLib, so their test is in the DefaultLib repo (tests/bigint_conversions.ts, linked PR). It passes under gc, rc, none and own.

Validated on Windows: ctest 6213/6213; DefaultLib release passes under gc (175), rc and none (174 + 1 gc-only skip), own (164 + 11 not-own skips).

Not changed:

  • 10n / 0n is still a hardware divide fault rather than JavaScript's RangeError;
  • ** on bigints still goes through number.

Found, not fixed: under rc, none and own, assert(new Number(5).toString() == "5", ...) crashes at run time. It's unrelated to this change.

🤖 Generated with Claude Code

…nvert

- A bigint literal is typed `bigint` (it was a plain i64). `x ?? 7n` of an
  optional bigint failed in LLVM (`bigint | i64`, and an i64 compared with
  a null pointer), and `5n` given for `bigint | string` was an invalid
  cast. `??` also takes a bigint for a value that is never null.
- A literal that does not fit 64 bits is an error: 12345678901234567890n
  printed -6101065172474983726.
- `/`, `%`, shifts and bitwise operators of bigints stay 64-bit integers:
  `10n / 3n` was 3.33333 through a number, and `1n << 40n` was 256, shifted
  by 40 mod 32 through an i32.
- `Number(x)`, `BigInt(x)`, `String(x)` and `Boolean(x)` called without
  `new` convert to the primitive, as in JavaScript: they made the class's
  object, so `BigInt(42) + 1n` and `Number(x) + 0.5` were invalid casts.

Tests: 00bigint_ops (gc, rc, none),
diagnostic-location/bigint_literal_out_of_range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 0526535 into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the bigint-cluster branch October 29, 2026 00:29
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