read_f64: Read floating point values from a connection

View source: R/read-float.R

read_f64R Documentation

Read floating point values from a connection

Description

Read floating point numbers into a standard R vector of doubles

Usage

read_f64(con, n = 1, endian = NULL)

read_f32(con, n = 1, endian = NULL)

read_f16(con, n = 1, endian = NULL)

read_bfloat(con, n = 1, endian = NULL)

read_dbl(con, n = 1, endian = NULL)

read_float(con, n = 1, endian = NULL)

read_half(con, n = 1, endian = NULL)

Arguments

con

Connection object or raw vector. Connection objects can be created with file(), url(), rawConnection() or any of the other many connection creation functions.

n

Number of elements to read. Default: 1

endian

Ordering of bytes within the file when reading multi-byte values. Possible values: 'big' or 'little'. Default: NULL indicates that endian option should be retrieved from the connection object if possible (where the user has used set_endian()) or otherwise will be set to "little"

Details

double precision

8 byte floating point numbers. read_f64() also available as read_dbl()

single precision

4 byte floating point numbers. read_f32() also available as read_float()

half precision

2 byte floating point numbers. read_f16() also available as read_half(). Consists of 1 sign bit, 5 bits for exponent and 10 bits for fraction.

bfloat

2 byte floating point numbers in the bfloat format read_bfloat(). Consits of 1 sign bit, 8 bits fo exponent and 7 bits for fraction.

Value

vector of double precision floating point numbers

See Also

Other data input functions: read_hex(), read_raw(), read_str(), read_uint8(), scan_dbl()

Examples

# Raw vector with 16 bytes (128 bits) of dummy data
data <- as.raw(1:16)
con <- rawConnection(data, 'rb')
read_f64(con, n = 1) # Read a 64-bit double-precision number
read_f16(con, n = 4) # Read 4 x 16-bit half-precision number
close(con)


ctypesio documentation built on April 3, 2025, 7:28 p.m.