i64: Wasm value type
The i64 value type holds a 64-bit integer.
Syntax
;; Function returning an i64 constant
(func (result i64)
i64.const 9000000000
)
;; i64 parameter and local
(func (param $p i64) (local $tmp i64)
;; ...
)
;; Mutable i64 global
(global $count (mut i64) (i64.const 0))
Description
i64 values are 64 bits wide and are not inherently signed or unsigned. Each instruction chooses its interpretation: signed variants such as i64.div_s treat operands as two's-complement, whereas unsigned variants such as i64.div_u do not. Operations whose result is unaffected by signedness, such as addition, subtraction, multiplication, and bitwise operations, have a single instruction.
i64 is transparent: its bit pattern is observable, and i64 values may be stored in linear memory.
i64 intergration with JavaScript BigInt
JavaScript's Number type cannot losslessly represent the full i64 range, therefore i64 values are converted to BigInt values (and vice versa) when they cross the JavaScript boundary; for example, when exporting or importing functions involving i64 parameters or return values.
When exporting a Wasm function with the signature: [i64] -> [i64], the parameter has to be expressed as a BigInt value:
const result = wasmInstance.exports.myFunc(42n);
console.log(result); // also a BigInt
An i64 return value becomes a BigInt in JavaScript automatically.
When moving from JavaScript over to Wasm, a BigInt passed as an i64 argument is truncated to 64 bits, wrapped modulo 2⁶⁴. Passing a plain Number where an i64 is expected throws a TypeError.
Specifications
| Specification |
|---|
| Unknown specification> # syntax-numtype> |