Qu

read_int64

Builtin index · File I/O

result = read_int64(f, [endian=])

Input: f, endian · Output: result

What it is

Reads a signed 64-bit integer from f (file handle, opened readable). endian (string, optional, default "little", or "big") selects byte order.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = read_int64(f, [endian=])
f —Reads a signed 64-bit integer from f (file handle, opened readable).
endian string, optionalendian (string, optional, default "little", or "big") selects byte order.
result number
Returns a number, or Nothing if fewer than 8 bytes remain. Every Value here is an f64, exact only up to 2^53 — a value outside -2^53..=2^53 (about 9 quadrillion) comes back rounded to the nearest representable double, silently losing its low bits, the same limitation any language whose only numeric type is a double has (JavaScript's Number, for one).

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

f = fopen("sample64.bin", "wb")
write_int64(f, -123456789012)
write_uint64(f, 9007199254740993)   # 1 past 2^53 -- the exact-precision edge

close(f)

g = fopen("sample64.bin", "rb")
a = read_int64(g)
b = read_uint64(g)
close(g)
print("{a} {b}")               # -123456789012 9007199254740992 -- rounded


M = [1, 2, 3; 4, 5, 6]
write_array("matrix.bin", M, type = "int32")
back = read_array("matrix.bin", type = "int32") -> (2, 3)
print(back)                    # [1, 2, 3; 4, 5, 6] -- shape recovered via reshape

output
-123456789012 9007199254740992
[1, 2, 3; 4, 5, 6]

from file-io