write_double
write_double(f, n, [endian=])
Input: f, n, endian · Output: no output
What it is
Writes n (number) to f (file handle, opened writable/appendable) as a 64-bit IEEE-754 float. endian (string, optional, default "little", or "big") selects byte order.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
write_double(f, n, [endian=]) | f numberWrites n (number) to f (file handle, opened writable/appendable) as a 64-bit IEEE-754 float.n numberWrites n (number) to f (file handle, opened writable/appendable) as a 64-bit IEEE-754 float.endian string, optionalendian (string, optional, default "little", or "big") selects byte order. | no output | — |
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("temps.bin", "wb")
write_double(f, 20.5)
write_double(f, 21.0)
write_double(f, 19.8)
close(f)
print(file_size("temps.bin")) # 24 -- 3 doubles, 8 bytes each
g = fopen("temps.bin", "rb")
vals = read_values(g, "f64", 3)
close(g)
print(vals) # [20.5, 21, 19.8]
whole = read_array("temps.bin", type="f64")
print(whole) # [20.5, 21, 19.8]
output
24 [20.5, 21, 19.8] [20.5, 21, 19.8]
from file-io
f = fopen("records.bin", "wb")
write_double(f, 0.0)
write_uint16(f, 12)
write_double(f, 0.5)
write_uint16(f, 15)
close(f)
fields = [["t", "f64"], ["ch", "u16"]]
g = fopen("records.bin", "rb")
one = read_struct(g, fields)
close(g)
print(one.t) # 0
print(one.ch) # 12
h = fopen("records.bin", "rb")
tbl = read_structs(h, fields, 2)
close(h)
print(nrow(tbl)) # 2
print(tbl.ch) # [12, 15]
output
0 12 2 [12, 15]
from file-io
f = fopen("sample.bin", "wb")
write_int16(f, -5)
write_uint16(f, 300)
write_uint32(f, 70000)
write_double(f, 3.14159)
close(f)
g = fopen("sample.bin", "rb")
a = read_int16(g)
b = read_uint16(g)
c = read_uint32(g)
d = read_double(g)
close(g)
print("{a} {b} {c} {d}") # -5 300 70000 3.14159
output
-5 300 70000 3.14159
from file-io