MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / castToBigInt

Function castToBigInt

src/parseTools.mjs:280–295  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

278// XXX Make all i64 parts signed
279
280function 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

Callers 5

splitI64Function · 0.85
makeSetValueImplFunction · 0.85
makeReturn64Function · 0.85
toIndexTypeFunction · 0.85
to64Function · 0.85

Calls 1

absMethod · 0.45

Tested by

no test coverage detected