HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
tc39
proposal-bigint
HTML2017–2021
tc39 / proposal-bigint · Archived

proposal-bigint

Arbitrary precision integers in JavaScript

19Distinct people
22Mentions
0Explicit recommenders
561GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Arbitrary precision integers in JavaScript

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year22 dated mentions

Observed mentions: 2017-06-27 08:59:03 UTC to 2021-03-01 07:07:39 UTC.

0369122017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 5 mentions; 0 submissions, 5 comments20172018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 11 mentions; 2 submissions, 9 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 5 mentions; 0 submissions, 5 comments20192020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC505
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC1129
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC505
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC101

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
BigInt: Arbitrary precision integers in JavaScript Daniel Ehrenberg, Igalia. Stage 4 This proposal is complete and already merged into ECMA262 specification. See the specification text here. Thanks for help and feedback on this effort from Brendan Eich, Waldemar Horwat, Jaro Sevcik, Benedikt Meurer, Michael Saboff, Adam Klein, Sarah Groff-Palermo and others. Contents What Is It? How Does It Work? Syntax Example: Calculating Primes Operators Comparisons Conditionals Other API Notes Gotchas & Exceptions Interoperation with Number and String Rounding Cryptography Other Exceptions Usage Recommendations About the Proposal Motivation, Or Why Do We Need Such Big Numbers? Design Philosophy, Or Why Is This Like This? State of the Proposal What Is It? BigInt is a new primitive that provides a way to represent whole numbers larger than 253, which is the largest number Javascript can reliably represent with the Number primitive. const x = Number.MAX_SAFE_INTEGER; // ↪ 9007199254740991, this is 1 less than 2^53 const y = x + 1; // ↪ 9007199254740992, ok, checks out const z = x + 2 // ↪ 9007199254740992, wait, that’s the same as above! Learn more about how numbers are represented in Javascript in the slides from Daniel's talk at JSConfEU. How Does It Work? The following sections show BigInt in action. A number have been influenced by or taken outright from Mathias Bynens's BigInt v8 update, which includes more details than this page. Syntax A BigInt is created by appending n to the end of the integer or by calling the constructor. const theBiggestInt = 9007199254740991n; const alsoHuge = BigInt(9007199254740991); // ↪ 9007199254740991n const hugeButString = BigInt('9007199254740991'); // ↪ 9007199254740991n Example: Calculating Primes function isPrime(p) { for (let i = 2n; i * i <= p; i++) { if (p % i === 0n) return false; } return true; } // Takes a BigInt as an argument and returns a BigInt function nthPrime(nth) { let maybePrime = 2n; let prime = 0n; while (nth >= 0n) { if (isPrime(maybePrime)) { nth -= 1n; prime = maybePrime; } maybePrime += 1n; } return prime; } Operators You can use +, *, -, ** and % with BigInts, just like with Numbers. const previousMaxSafe = BigInt(Number.MAX_SAFE_INTEGER); // ↪ 9007199254740991 const maxPlusOne = previousMaxSafe + 1n; // ↪ 9007199254740992n const theFuture = previousMaxSafe + 2n; // ↪ 9007199254740993n, this works now! const multi = previousMaxSafe * 2n; // ↪ 18014398509481982n const subtr = multi – 10n; // ↪ 18014398509481972n const mod = multi % 10n; // ↪ 2n const bigN = 2n ** 54n; // ↪ 18014398509481984n bigN * -1n // ↪ –18014398509481984n The / operator also work as expected with whole numbers. However, since these are BigInts and not BigDecimals, this operation will round towards 0, which is to say, it will not return any fractional digits. const expected = 4n / 2n; // ↪ 2n const rounded = 5n / 2n; // ↪ 2n, not 2.5n See the advanced documentation for use with bitwise operators. Comparisons A BigInt is not strictly equal to a Number, but it is loosely so. 0n === 0 // ↪ false 0n == 0 // ↪ true Numbers and BigInts may be compared as usual. 1n < 2 // ↪ true 2n > 1 // ↪ true 2 > 2 // ↪ false 2n > 2 // ↪ false 2n >= 2 // ↪ true They may be mixed in arrays and sorted. const mixed = [4n, 6, -12n, 10, 4, 0, 0n]; // ↪  [4n, 6, -12n, 10, 4, 0, 0n] mixed.sort(); // ↪ [-12n, 0, 0n, 10, 4n, 4, 6] Conditionals A BigInt behaves like a Number in cases where it is converted to a Boolean: if, ||, &&, Boolean, !. if (0n) { console.log('Hello from the if!'); } else { console.log('Hello from the else!'); } // ↪ "Hello from the else!" 0n || 12n // ↪ 12n 0n && 12n // ↪ 0n Boolean(0n) // ↪ false Boolean(12n) // ↪ true !12n // ↪ false !0n // ↪ true Other API Notes BigInts may also be used in BigInt64Array and BigUint64Array typed arrays for 64-bit integers. const view = new BigInt64Array(4); // ↪ [0n, 0n, 0n, 0n] view.length; // ↪ 4 view[0]; // ↪ 0n view[0] = 42n; view[0]; // ↪ 42n // Highest possible BigInt value that can be represented as a // signed 64-bit integer. const max = 2n ** (64n - 1n) - 1n; view[0] = max; view[0]; // ↪ 9_223_372_036_854_775_807n view[0] = max + 1n; view[0]; // ↪ -9_223_372_036_854_775_808n // ^ negative because of overflow For more about BigInt library functions, see the advanced section. Gotchas & Exceptions Interoperation with Number and String The biggest surprise may be that BigInts cannot be operated on interchangeably with Numbers. Instead a TypeError will be thrown. (Read the design philosophy for more about why this decision was made.) 1n + 2 // ↪ TypeError: Cannot mix BigInt and other types, use explicit conversions 1n * 2 // ↪ TypeError: Cannot mix BigInt and other types, use explicit conversions BigInts also cannot be converted to Numbers using the unary +. Number must be used. +1n // ↪ TypeError: Cannot convert a BigInt value to a number Number(1n) // ↪ 1 The BigInt can however be concatenated with a String. 1n + '2' // ↪ "12" '2' + 1n // ↪ "21" For this reason, it is recommended to continue using Number for code which will only encounter values under 253. Reserve BigInt for cases where large values are expected. Otherwise, by converting back and forth, you may lose the very precision you are hoping to preserve. const largeFriend = 900719925474099267n; const alsoLarge = largeFriend + 2n; const sendMeTheBiggest = (n, m) => Math.max(Number(n), Number(m)); sendMeTheBiggest(largeFriend, alsoLarge) // ↪900719925474099300 // This is neither argument! Reserve Number values for cases when they are integers up to 253, for other cases, using a string (or a BigInt literal) would be advisable to not lose precision. const badPrecision = BigInt(9007199254740993); // ↪9007199254740992n const goodPrecision = BigInt('9007199254740993'); // ↪9007199254740993n const alsoGoodPrecision = 9007199254740993n; // ↪9007199254740993n Rounding As noted above, the B
Read the full README on GitHub

What Hacker News says

22 sources
You could use the same technique as asm.js for acquiring and handling integers. Unary `+` always produces a Number or an exception. Bitwise operators treat their operands as a sequence of 32 bits, so a bitwise OR with 0 will cast the value to a 32-bit integer: +value|0 There's also TypedArray [0]. I think you'll be interested in the BigInt proposal [1] [2], which is stage 3. It's already available in Chrome, and behind a flag in Firefox. Now that it's possible to accurately represent 64-bit values, we're getting BigInt64Array and BigUint64Array. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [1] https://github.com/tc39/proposal-bigint [2] http://2ality.com/2017/03/es-integer.html
In Future JavaScript: what is still missing?
I really wish we had a JSON 2 format which could fix JSON's obvious shortcomings. I would like to see: - Support for Maps and Sets (unlike objects, maps allow arbitrary types to be used as keys) - A standard Date format - Embedded binary blobs. No idea how to do this and keep it human readable, but when you need this its super useful. Maybe something similar to WS's binary message encoding. - Arbitrary precision integer support. This is particularly useful for cryptocurrencies and for interoperability with 64 bit integers in other languages. And bigints are coming to javascript - https://github.com/tc39/proposal-bigint - Maybe even fix JSON's weird unicode encoding: http://timelessrepo.com/json-isnt-a-javascript-subset Unfortunately it seems like nobody 'owns' JSON enough to give JSON 2.0 the political weight it would need for cross-langu
Read the rest
age support.
In Data serialization
I've implemented support in the Scala.js compiler to emit Longs (64-bit signed integers) as BigInts about 6 weeks ago. [1] Unfortunately, without specific optimizations that are not part of the baseline currently implemented in V8, this implementation is very slow. It's up to 60x slower than our production implementation. [2] I'm looking forward to seeing small BigInts being optimized as native 64-bit values! [1] https://github.com/scala-js/scala-js/pull/3286/commits/deec9... [2] https://github.com/tc39/proposal-bigint/issues/117
In Adding BigInts to V8

Showing the 15 most recent of 22 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.