(x)
| 278 | // XXX Make all i64 parts signed |
| 279 | |
| 280 | function castToBigInt(x) { |
| 281 | // Micro-size-optimization: if x is an integer literal, then we can append |
| 282 | // the suffix 'n' instead of casting to BigInt(), to get smaller code size. |
| 283 | var n = Number(x); |
| 284 | if (Number.isInteger(n) && isFinite(n)) { |
| 285 | // NOTE: BigInt(316059037807746200000) != 316059037807746200000n |
| 286 | // i.e. constructing numbers with BigInt()s is subject to rounding, if |
| 287 | // the input value cannot be exactly represented as a 64-bit double. |
| 288 | // Currently the test suite depends on this rounding behavior, so only |
| 289 | // apply this literal optimization to safe integers for now. |
| 290 | if (Math.abs(n) < Number.MAX_SAFE_INTEGER) { |
| 291 | return `${x}n`; |
| 292 | } |
| 293 | } |
| 294 | return `BigInt(${x})`; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | // Splits a number (an integer in a double, possibly > 32 bits) into an i64 |
no test coverage detected