f16

package
v0.0.0-...-6c7272e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package f16 is a basic math library for 16 bit floating point numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

type Number uint16

Number represents a 16-bit floating point number, containing a single sign bit, 5 exponent bits and 10 fractional bits. This corresponds to IEEE 754-2008 binary16 (or half precision float) type.

 MSB                                                                         LSB
╔════╦════╤════╤════╤════╤════╦════╤════╤════╤════╤════╤════╤════╤════╤════╤════╗
║Sign║ E₄ │ E₃ │ E₂ │ E₁ │ E₀ ║ F₉ │ F₈ │ F₇ │ F₆ │ F₅ │ F₄ │ F₃ │ F₂ │ F₁ │ F₀ ║
╚════╩════╧════╧════╧════╧════╩════╧════╧════╧════╧════╧════╧════╧════╧════╧════╝
Where E is the exponent bits and F is the fractional bits.

func From

func From(f32 float32) Number

From returns a Number encoding of a 32-bit floating point number. Infinities and NaNs are encoded as such. Very large and very small numbers get rounded to infinity and zero respectively.

func Inf

func Inf(sign int) Number

Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

func NaN

func NaN() Number

NaN returns an “not-a-number” value.

func (Number) Float32

func (f Number) Float32() float32

Float32 returns the Number value expanded to a float32. Infinities and NaNs are expanded as such.

func (Number) IsInf

func (f Number) IsInf(sign int) bool

IsInf reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.

func (Number) IsNaN

func (f Number) IsNaN() bool

IsNaN reports whether f is an “not-a-number” value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL