Documentation
¶
Index ¶
- Constants
- Variables
- func Encode(value DFloat, writer io.Writer) (bytesEncoded int, err error)
- func EncodeBig(value *apd.Decimal, writer io.Writer) (bytesEncoded int, err error)
- func EncodeBigToBytes(value *apd.Decimal, buffer []byte) (bytesEncoded int)
- func EncodeInfinity(buffer []byte) (bytesEncoded int)
- func EncodeNegativeInfinity(buffer []byte) (bytesEncoded int)
- func EncodeNegativeZero(buffer []byte) (bytesEncoded int)
- func EncodeQuietNan(buffer []byte) (bytesEncoded int)
- func EncodeSignalingNan(buffer []byte) (bytesEncoded int)
- func EncodeToBytes(value DFloat, buffer []byte) (bytesEncoded int)
- func EncodeZero(buffer []byte) (bytesEncoded int)
- func MaxEncodeLength() int
- func MaxEncodeLengthBig(value *apd.Decimal) int
- func RoundingError() error
- type DFloat
- func DFloatFromAPD(value *apd.Decimal) (DFloat, error)
- func DFloatFromBigFloat(value *big.Float) (DFloat, error)
- func DFloatFromBigInt(value *big.Int) (DFloat, error)
- func DFloatFromFloat64(value float64, significantDigits int) (DFloat, error)
- func DFloatFromString(str string) (DFloat, error)
- func DFloatFromUInt(value uint64) (DFloat, error)
- func DFloatValue(exponent int32, coefficient int64) DFloat
- func Decode(reader io.Reader) (value DFloat, bigValue *apd.Decimal, bytesDecoded int, err error)
- func DecodeWithByteBuffer(reader io.Reader, buffer []byte) (value DFloat, bigValue *apd.Decimal, bytesDecoded int, err error)
- func Infinity() DFloat
- func NegativeInfinity() DFloat
- func NegativeZero() DFloat
- func QuietNaN() DFloat
- func SignalingNaN() DFloat
- func Zero() DFloat
- func (this DFloat) APD() *apd.Decimal
- func (this DFloat) BigFloat() *big.Float
- func (this DFloat) BigInt() (*big.Int, error)
- func (this DFloat) Float() float64
- func (this DFloat) Int() (int64, error)
- func (this DFloat) IsInfinity() bool
- func (this DFloat) IsNan() bool
- func (this DFloat) IsNegativeInfinity() bool
- func (this DFloat) IsNegativeZero() bool
- func (this DFloat) IsSignalingNan() bool
- func (this DFloat) IsSpecial() bool
- func (this DFloat) IsZero() bool
- func (this DFloat) String() string
- func (this DFloat) Text(format byte) string
- func (this DFloat) Uint() (uint64, error)
Constants ¶
const ( CoeffNegativeZero = 0 CoeffInfinity = 1 CoeffNegativeInfinity = 5 CoeffNan = 2 CoeffSignalingNan = 6 )
const ExpSpecial = int32(-0x80000000)
An exponent value of ExpSpecial indicates that this is a special value. The coefficient will be a special code that determines what special value is represented (CoeffInfinity, CoeffNan, etc).
Variables ¶
var ErrorIncomplete = fmt.Errorf("Compact float value is incomplete")
Functions ¶
func EncodeBigToBytes ¶ added in v1.5.0
Encodes an apt.Decimal to a buffer. Assumes the buffer is big enough (see MaxEncodeLengthBig()).
func EncodeInfinity ¶ added in v1.2.1
Encodes positive infinity, using 2 bytes.
func EncodeNegativeInfinity ¶ added in v1.3.1
Encodes negative infinity, using 2 bytes.
func EncodeNegativeZero ¶ added in v1.3.1
Encodes negative zero, using 1 byte.
func EncodeQuietNan ¶ added in v1.3.1
Encodes a quiet NaN, using 2 bytes.
func EncodeSignalingNan ¶ added in v1.3.1
Encodes a signaling NaN, using 2 bytes.
func EncodeToBytes ¶ added in v1.5.0
Encodes a DFloat to a byte buffer. Assumes the buffer is big enough (see MaxEncodeLength()).
func EncodeZero ¶ added in v1.2.1
Encodes positive zero, using 1 byte.
func MaxEncodeLength ¶ added in v1.1.0
func MaxEncodeLength() int
Maximum number of bytes required to encode a DFloat.
func MaxEncodeLengthBig ¶ added in v1.3.4
Maximum number of bytes required to encode a particular apd.Decimal. This is an estimate; it may be smaller, but never bigger.
func RoundingError ¶ added in v1.6.0
func RoundingError() error
Types ¶
type DFloat ¶ added in v1.3.0
DFloat represents a decimal floating point value in 96 bits. It supports coefficient values within the range of int64, and exponent values from -0x7fffffff to 0x7fffffff. The exponent -0x80000000 (ExpSpecial) is used to indicate special values, and is not allowed as an actual exponent value.
func DFloatFromAPD ¶ added in v1.3.0
Convert an apd.Decimal to DFloat. If the value is too big to fit, its lower significant digits will be rounded (half-to-even) and RoundingError will be returned along with the rounded value.
func DFloatFromBigFloat ¶ added in v1.4.6
Convert a big.Float to DFloat. If the value is too big to fit, its lower significant digits will be rounded (half-to-even) and RoundingError will be returned along with the rounded value.
func DFloatFromBigInt ¶ added in v1.3.5
Convert a big.Int to DFloat. If the value is too big to fit, its lower significant digits will be rounded (half-to-even) and RoundingError will be returned along with the rounded value.
func DFloatFromFloat64 ¶ added in v1.3.0
Convert an iee754 binary floating point value to DFloat, with the specified number of significant digits. Rounding is half-to-even, meaning it rounds towards an even number when exactly halfway. If rounding occurs, the returned error will be RoundingError. If significantDigits is less than 1, no rounding takes place.
func DFloatFromString ¶ added in v1.3.0
Convert a string float representation to DFloat. If the value is too big to fit, its lower significant digits will be rounded (half-to-even) and RoundingError will be returned along with the rounded value.
func DFloatFromUInt ¶ added in v1.3.5
Convert an unsigned int to DFloat. If the value is too big to fit, its lowest significant digit will be rounded (half-to-even) and RoundingError will be returned along with the rounded value.
func DFloatValue ¶ added in v1.3.0
func Decode ¶
Decode a float. bigValue will be nil unless the decoded value is too big to fit into a DFloat.
func DecodeWithByteBuffer ¶ added in v1.5.0
func DecodeWithByteBuffer(reader io.Reader, buffer []byte) (value DFloat, bigValue *apd.Decimal, bytesDecoded int, err error)
Decode a float using the supplied single-byte buffer. bigValue will be nil unless the decoded value is too big to fit into a DFloat.
func NegativeInfinity ¶ added in v1.3.2
func NegativeInfinity() DFloat
func NegativeZero ¶ added in v1.3.2
func NegativeZero() DFloat
func SignalingNaN ¶ added in v1.3.2
func SignalingNaN() DFloat
func (DFloat) APD ¶ added in v1.3.0
Returns the apd.Decimal representation of this value. All DFloat values can be represented as apd.Decimal.
func (DFloat) BigInt ¶ added in v1.4.3
Returns the big.Int representation of this value. Returns an error if the value is not a whole number.
func (DFloat) Float ¶ added in v1.3.0
Returns the float64 representation of this value. The result will be rounded according to strconv.ParseFloat() if it doesn't fit.
func (DFloat) Int ¶ added in v1.4.1
Returns the int64 representation of this value. Returns an error if the value cannot fit.
func (DFloat) IsInfinity ¶ added in v1.3.0
Returns true if the value is positive or negative infinity
func (DFloat) IsNegativeInfinity ¶ added in v1.3.0
func (DFloat) IsNegativeZero ¶ added in v1.3.0
func (DFloat) IsSignalingNan ¶ added in v1.3.0
func (DFloat) Text ¶ added in v1.3.3
Text converts the floating-point number x to a string according to the given format. The format is one of:
'e' -d.dddde±dd, decimal exponent, exponent digits 'E' -d.ddddE±dd, decimal exponent, exponent digits 'f' -ddddd.dddd, no exponent 'g' like 'e' for large exponents, like 'f' otherwise 'G' like 'E' for large exponents, like 'f' otherwise
If format is a different character, Text returns a "%" followed by the unrecognized.Format character. The 'f' format has the possibility of displaying precision that is not present in the Decimal when it appends zeros. All other formats always show the exact precision of the Decimal.
This method call is forwarded to *apd.Decimal.Text()