type Float16 … type Precision … const PrecisionExact … const PrecisionUnknown … const PrecisionInexact … const PrecisionUnderflow … const PrecisionOverflow … // PrecisionFromfloat32 returns Precision without performing // the conversion. Conversions from both Infinity and NaN // values will always report PrecisionExact even if NaN payload // or NaN-Quiet-Bit is lost. This function is kept simple to // allow inlining and run < 0.5 ns/op, to serve as a fast filter. func PrecisionFromfloat32(f32 float32) Precision { … } // Frombits returns the float16 number corresponding to the IEEE 754 binary16 // representation u16, with the sign bit of u16 and the result in the same bit // position. Frombits(Bits(x)) == x. func Frombits(u16 uint16) Float16 { … } // Fromfloat32 returns a Float16 value converted from f32. Conversion uses // IEEE default rounding (nearest int, with ties to even). func Fromfloat32(f32 float32) Float16 { … } const ErrInvalidNaNValue … type float16Error … func (e float16Error) Error() string { … } // FromNaN32ps converts nan to IEEE binary16 NaN while preserving both // signaling and payload. Unlike Fromfloat32(), which can only return // qNaN because it sets quiet bit = 1, this can return both sNaN and qNaN. // If the result is infinity (sNaN with empty payload), then the // lowest bit of payload is set to make the result a NaN. // Returns ErrInvalidNaNValue and 0x7c01 (sNaN) if nan isn't IEEE 754 NaN. // This function was kept simple to be able to inline. func FromNaN32ps(nan float32) (Float16, error) { … } // NaN returns a Float16 of IEEE 754 binary16 not-a-number (NaN). // Returned NaN value 0x7e01 has all exponent bits = 1 with the // first and last bits = 1 in the significand. This is consistent // with Go's 64-bit math.NaN(). Canonical CBOR in RFC 7049 uses 0x7e00. func NaN() Float16 { … } // Inf returns a Float16 with an infinity value with the specified sign. // A sign >= returns positive infinity. // A sign < 0 returns negative infinity. func Inf(sign int) Float16 { … } // Float32 returns a float32 converted from f (Float16). // This is a lossless conversion. func (f Float16) Float32() float32 { … } // Bits returns the IEEE 754 binary16 representation of f, with the sign bit // of f and the result in the same bit position. Bits(Frombits(x)) == x. func (f Float16) Bits() uint16 { … } // IsNaN reports whether f is an IEEE 754 binary16 “not-a-number” value. func (f Float16) IsNaN() bool { … } // IsQuietNaN reports whether f is a quiet (non-signaling) IEEE 754 binary16 // “not-a-number” value. func (f Float16) IsQuietNaN() bool { … } // IsInf reports whether f is an infinity (inf). // A sign > 0 reports whether f is positive inf. // A sign < 0 reports whether f is negative inf. // A sign == 0 reports whether f is either inf. func (f Float16) IsInf(sign int) bool { … } // IsFinite returns true if f is neither infinite nor NaN. func (f Float16) IsFinite() bool { … } // IsNormal returns true if f is neither zero, infinite, subnormal, or NaN. func (f Float16) IsNormal() bool { … } // Signbit reports whether f is negative or negative zero. func (f Float16) Signbit() bool { … } // String satisfies the fmt.Stringer interface. func (f Float16) String() string { … } // f16bitsToF32bits returns uint32 (float32 bits) converted from specified uint16. func f16bitsToF32bits(in uint16) uint32 { … } // f32bitsToF16bits returns uint16 (Float16 bits) converted from the specified float32. // Conversion rounds to nearest integer with ties to even. func f32bitsToF16bits(u32 uint32) uint16 { … }