Documentation ¶
Overview ¶
Package extended provides conversions to and from 80-bit "extended" floating-point numbers (float80).
Note that while NaNs are handled by this package, the distinction between quiet NaN and signaling NaN is not preserved during conversions.
Index ¶
- Constants
- Variables
- type Extended
- func (e Extended) Append(buf []byte, fmt byte, prec int) []byte
- func (e Extended) BigFloat() (*big.Float, error)
- func (e Extended) Float64() float64
- func (e Extended) Format(s fmt.State, format rune)
- func (e Extended) PutBytes(order binary.ByteOrder, b []byte)
- func (e Extended) PutBytesBigEndian(b []byte)
- func (e Extended) PutBytesLittleEndian(b []byte)
- func (e Extended) String() string
- func (e Extended) Text(format byte, prec int) string
Constants ¶
const ByteSize = 10
ByteSize is the size, in bytes, of the binary representation of an extended-precision float.
Variables ¶
var ErrIsNaN = errors.New("value is NaN")
ErrIsNaN indicates that the value is NaN and cannot be converted.
Functions ¶
This section is empty.
Types ¶
type Extended ¶
type Extended struct { // The sign is stored as the high bit. The low 15 bits contain the exponent, // with a bias of 16383. SignExponent uint16 // The fraction includes a ones place as the high bit. The value in the ones // place may be zero. Fraction uint64 }
An Extended is an 80-bit extended precision floating-point number.
func FromBytes ¶
FromBytes deserializes an extended-precision float from its binary representation. The binary representation takes 10 bytes.
func FromBytesBigEndian ¶
FromBytesBigEndian deserializes an extended-precision float from its binary representation in big endian. The binary representation takes 10 bytes.
func FromBytesLittleEndian ¶
FromBytesLittleEndian deserializes an extended-precision float from its binary representation in little endian. The binary representation takes 10 bytes.
func FromFloat64 ¶
FromFloat64 converts a 64-bit floating-point number to an 80-bit extended floating-point number.
func (Extended) Append ¶
Append appends the string form of the number to buf and returns the result.
func (Extended) BigFloat ¶
BigFloat converts the number to an arbitrary-precision float. Returns ErrIsNaN if the value is NaN, because NaN cannot be represented by big.Float.
func (Extended) Float64 ¶
Float64 returns the value of this 80-bit floating-point number as a float64. The result is rounded to the nearest float64, breaking ties towards even in the least-significant bit. Values which, after rounding, would be outside the range of a float64 are flushed to zero or infinity.
func (Extended) PutBytes ¶
PutBytes serializes the value as binary and writes it to a byte array. The binary representation takes 10 bytes.
func (Extended) PutBytesBigEndian ¶
PutBytesBigEndian serializes the value as a big-endian binary value and writes it to a byte array. The binary representation takes 10 bytes.
func (Extended) PutBytesLittleEndian ¶
PutBytesLittleEndian serializes the value as a little-endian binary value and writes it to a byte array. The binary representation takes 10 bytes.