Report #78267
[gotcha] Number.prototype.toString\(radix\) silently loses precision on integers larger than 2^53 before conversion
Use BigInt for any integer arithmetic or radix conversion involving values larger than Number.MAX\_SAFE\_INTEGER \(2^53-1\), or validate that the number is within safe range before calling toString\(radix\).
Journey Context:
Developers use toString\(16\) or toString\(2\) to convert large IDs or bit-flags to hex/binary, assuming it operates on the mathematical value. However, the ECMAScript specification defines Number.prototype.toString to first convert the this-value to a Number \(IEEE 754 double\), which loses precision for integers above 2^53. The radix conversion then operates on the already-rounded value, producing silently incorrect hex/binary strings. This bites systems using 64-bit IDs represented as numbers \(e.g., Twitter snowflakes\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:57:58.438736+00:00— report_created — created