Documentation ¶
Overview ¶
Package dnum implements decimal floating point numbers.
Uses uint64 to hold the coefficient and int8 for exponent. Only uses 16 decimal digits.
Value is sign * .coef * 10^exp, i.e. assumed decimal to left Coefficient is kept "maximized" in 16 decimal digits. Zeroed value is 0.
Index ¶
- Variables
- func Compare(x, y Dnum) int
- func Equal(x, y Dnum) bool
- type Dnum
- func Add(x, y Dnum) Dnum
- func Div(x, y Dnum) Dnum
- func FromFloat(f float64) Dnum
- func FromInt(n int64) Dnum
- func FromStr(s string) Dnum
- func Inf(sign int8) Dnum
- func Mul(x, y Dnum) Dnum
- func New(sign int8, coef uint64, exp int) Dnum
- func Raw(sign int8, coef uint64, exp int) Dnum
- func Sub(x, y Dnum) Dnum
- func (dn Dnum) Abs() Dnum
- func (dn Dnum) Coef() uint64
- func (dn Dnum) Exp() int
- func (dn Dnum) Format(mask string) string
- func (dn Dnum) Frac() Dnum
- func (dn Dnum) Hash() uint64
- func (dn Dnum) IsInf() bool
- func (dn Dnum) IsZero() bool
- func (dn Dnum) Neg() Dnum
- func (dn Dnum) Round(r int, mode RoundingMode) Dnum
- func (dn Dnum) Sign() int
- func (dn Dnum) String() string
- func (dn Dnum) ToFloat() float64
- func (dn Dnum) ToInt() (int, bool)
- func (dn Dnum) ToInt64() (int64, bool)
- func (dn Dnum) Trunc() Dnum
- type RoundingMode
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Zero = Dnum{} One = Dnum{1000_0000_0000_0000, signPos, 1} NegOne = Dnum{1000_0000_0000_0000, signNeg, 1} PosInf = Dnum{1, signPosInf, 0} NegInf = Dnum{1, signNegInf, 0} )
common values
Functions ¶
Types ¶
type Dnum ¶
type Dnum struct {
// contains filtered or unexported fields
}
Dnum is a decimal floating point number
func FromStr ¶
FromStr parses a numeric string and returns a Dnum representation. It panics for invalid input.
func New ¶
New constructs a Dnum, maximizing coef and handling exp out of range Used to normalize results of operations
func Raw ¶
Raw constructs a Dnum without normalizing - arguments must be valid. Used by SuDnum Unpack
Click to show internal directories.
Click to hide internal directories.