Skip to contents

Real bit manipulation: round-to-nearest-even via R's storage.mode coercion is unavailable for float16 in base R, so the cast is done by hand – extract sign/exponent/mantissa from the double, then round the mantissa to 10 bits with ties-to-even, handling overflow to Inf and underflow to subnormal/zero exactly as IEEE-754 requires.

Usage

morie_geron_fp16_quant(x)

Arguments

x

Values to cast.

Value

List with value, sign, exponent, mantissa_field, rel_error, overflowed, underflowed.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_fp16_quant(V)
#> $value
#> [1] 1 2 3 4 5 6 7 8
#> 
#> $sign
#> [1] 0 0 0 0 0 0 0 0
#> 
#> $exponent
#> [1] 0 1 1 2 2 2 2 3
#> 
#> $exponent_field
#> [1] 15 16 16 17 17 17 17 18
#> 
#> $mantissa_field
#> [1]   0   0 512   0 256 512 768   0
#> 
#> $rel_error
#> [1] 0 0 0 0 0 0 0 0
#> 
#> $max_rel_error
#> [1] 0
#> 
#> $overflowed
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> 
#> $underflowed
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> 
#> $eps
#> [1] 0.0009765625
#> 
#> $max_normal
#> [1] 65504
#> 
#> $min_normal
#> [1] 6.103516e-05
#> 
#> $bits_total
#> [1] 16
#> 
#> $estimate
#> [1] 0
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "IEEE-754 binary16 round-trip with field decomposition and range diagnostics"
#>