Skip to contents

Keeps the top 16 bits of the binary32 encoding: 1 sign, 8 exponent, 7 mantissa bits. Default rounding is round-to-nearest ties-to-even, as hardware does; "truncate" drops the low bits. NaN lanes are restored so a rounding carry cannot turn a NaN into an infinity.

Usage

morie_geron_bf16(x, rounding = "nearest_even")

Arguments

x

Values to quantise.

rounding

"nearest_even" or "truncate".

Value

List with values, bits (16-character strings), abs_error, rel_error, max_rel_error, mantissa_bits, exponent_bits.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_bf16(V)
#> $values
#> [1] 1 2 3 4 5 6 7 8
#> 
#> $bits
#> [1] "0011111110000000" "0100000000000000" "0100000001000000" "0100000010000000"
#> [5] "0100000010100000" "0100000011000000" "0100000011100000" "0100000100000000"
#> 
#> $abs_error
#> [1] 0 0 0 0 0 0 0 0
#> 
#> $rel_error
#> [1] 0 0 0 0 0 0 0 0
#> 
#> $max_rel_error
#> [1] 0
#> 
#> $mantissa_bits
#> [1] 7
#> 
#> $exponent_bits
#> [1] 8
#> 
#> $rounding
#> [1] "nearest_even"
#> 
#> $estimate
#> [1] 1
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "BF16 quantisation (1 sign / 8 exponent / 7 mantissa bits)"
#>