{"id":17142924,"url":"https://github.com/js-choi/proposal-bigint-bit-length","last_synced_at":"2026-03-12T06:01:40.466Z","repository":{"id":45376681,"uuid":"513581129","full_name":"js-choi/proposal-bigint-bit-length","owner":"js-choi","description":"Draft specification for BigInt bit length in JavaScript.","archived":false,"fork":false,"pushed_at":"2022-07-14T18:28:04.000Z","size":112,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T10:42:52.788Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/js-choi.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-13T15:47:01.000Z","updated_at":"2023-08-18T13:55:12.000Z","dependencies_parsed_at":"2022-07-13T21:44:21.417Z","dependency_job_id":null,"html_url":"https://github.com/js-choi/proposal-bigint-bit-length","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/js-choi/proposal-bigint-bit-length","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-bigint-bit-length","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-bigint-bit-length/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-bigint-bit-length/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-bigint-bit-length/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/js-choi","download_url":"https://codeload.github.com/js-choi/proposal-bigint-bit-length/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-choi%2Fproposal-bigint-bit-length/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30416729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T04:41:02.746Z","status":"ssl_error","status_checked_at":"2026-03-12T04:40:12.571Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T20:33:12.670Z","updated_at":"2026-03-12T06:01:40.409Z","avatar_url":"https://github.com/js-choi.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BigInt bit length for JavaScript\nECMAScript Stage-0 Proposal. J. S. Choi, 2021.\n\n* **[Specification][]**\n* **Babel plugin**: Not yet\n\n[specification]: http://jschoi.org/21/es-bigint-math/\n\n## Problem space\nBigInts are important for a myriad of\nmathematical, financial, scientific, and timing applications\n(such as in the [Node.js `process.hrtime.bigint` API][hrtime]),\nand they have been therefore a valuable addition to JavaScript\nsince their standardization in ES 2021.\n\n[hrtime]: https://nodejs.org/api/process.html#process_process_hrtime_bigint\n\nBecause their length is theoretically unbound (unlike ordinary JavaScript\nNumbers), the bit lengths of their binary representations are an essential\ncharacteristic. They are particularly useful for calculating the log2 – for\nexample, [Waldemar Horwat’s integer-roots][] uses them to calculate the square\nand cube roots of BigInts.\n\nIn other languages, BigInt bit lengths are provided by convenient\nproperty/method APIs:\n\n| Precedent       | Form                         | Negative-int behavior          | Return type                   |\n| --------------- | ---------------------------- | ------------------------------ | ----------------------------- |\n| **[Python][]**  | `i.bit_length()`             | Absolute value of input        | Bignum integer                |\n| **[Java][]**    | `i.bitLength()`              | Two’s complement sans sign bit | 32-bit signed integer         |\n| **[.NET][]**    | `BigInteger.GetBitLength(i)` | Two’s complement sans sign bit | 64-bit signed integer         |\n| **[Dart][]**    | `i.bitLength`                | Two’s complement sans sign bit | 32- or 64-bit signed integer* |\n| **[Wolfram][]** | `BitLength[i]`               | Two’s complement sans sign bit | Bignum integer                |\n| **[GNP][]**     | `mpz_sizeinbase(i, 2)`       | Absolute value of input        | ≥16-bit signed integer        |\n\n\\* In Dart, the width of the return type depends on the device’s CPU.\n\n[Python]: https://docs.python.org/3/library/stdtypes.html#int.bit_length\n[Java]: https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#bitLength()\n[.NET]: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.getbitlength?view=net-6.0#system-numerics-biginteger-getbitlength\n[Dart]: https://api.dart.dev/stable/2.17.6/dart-core/BigInt/bitLength.html\n[Wolfram]: https://reference.wolfram.com/language/ref/BitLength.html\n[GNP]: https://gmplib.org/manual/Miscellaneous-Integer-Functions\n\nIn JavaScript, we currently have to [use `.toString` to count the BigInts’\ndigits][toString]. This is weird and inefficient for such a fundamental\noperation. We therefore propose exploring the addition of a BigInt bit-length\nAPI to the JavaScript language.\n\n[toString]: https://stackoverflow.com/questions/54758130/how-to-obtain-the-amount-of-bits-of-a-bigint\n\nIf this proposal is approved for Stage 1, then we would explore various\ndirections for the API’s design. We would also examine cross-cutting concerns\nwith other language features both standardized and proposed, such as the\n[BigInt Math proposal][].\n\n## Potential solutions\nThe solution would probably be a computed property or method on the\nBigInt.prototype object or a static function on the BigInt constructor –\nsomething like one of the following:\n\n```js\n(0n).bitLength // Like in Dart and Python.\n(0n).bitLength() // Like in Java.\n(0n).getBitLength()\nBigInt.bitLength(0n)\nBigInt.getBitLength(0n) // Like in .NET.\n```\n\nIt would probably return the number of bits in the minimal two’s-complement\nrepresentation of any input BigInt, excluding the sign bit. For positive\nBigInts, this is equivalent to the number of bits in their ordinary binary\nrepresentations. This is also roughly equivalent to `ceil(log2(value \u003c 0 ?\n-value : value + 1))`. (See [issue #3][] for discussion about other options.)\n\nThe resulting bit length might also be a BigInt, or it might be an ordinary\nNumber if we are fine with limiting BigInts to be less than `2n **\nBigInt(Number.MAX_SAFE_INTEGER)`. (In practice, this already happens; [V8\nalready caps BigInts to no more than `1\u003c\u003c30` bits, and Firefox already caps at\nabout `1\u003c\u003c20` bits][already capped]. The question thus is whether such a limit\nshould be enshrined in the specification. See [issue #2][].)\n\n[Waldemar Horwat’s integer-roots]: https://github.com/waldemarhorwat/integer-roots\n\nIn contrast to other operations – such as `abs` and `sqrt` from the [BigInt\nMath proposal][] – the new bit-length API would probably be useful only on\nBigInts and not on ordinary numbers. We therefore are not plannign to add it\nto the Math object. (But see [issue #4][] for more discussion.)\n\n[BigInt Math proposal]: https://github.com/tc39/proposal-bigint-math\n[already capped]: https://github.com/tc39/proposal-bigint-math/issues/21#issuecomment-1180917488\n[issue #2]: https://github.com/js-choi/proposal-bigint-bit-length/issues/2\n[issue #3]: https://github.com/js-choi/proposal-bigint-bit-length/issues/3\n[issue #4]: https://github.com/js-choi/proposal-bigint-bit-length/issues/4\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-bigint-bit-length","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-choi%2Fproposal-bigint-bit-length","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-choi%2Fproposal-bigint-bit-length/lists"}