Documentation ¶
Overview ¶
Package big extends the capabilities of standard "math/big" package by adding custom global precision to Float and Rat; and global rounding mode, and bits precision to Float.
Index ¶
- Variables
- type Float
- func AddFloat(f, g interface{}) *Float
- func CreateFloat(v float64) Float
- func MulFloat(f, g interface{}) *Float
- func MustParseFloat(s string) (f *Float)
- func NewFloat(v float64) *Float
- func ParseFloat(s string) (f *Float, err error)
- func QuoFloat(f, g interface{}) *Float
- func SubFloat(f, g *Float) *Float
- func (f *Float) Add(g interface{}) *Float
- func (f *Float) Clone() *Float
- func (f *Float) Int64() int64
- func (f *Float) IsEqual(g interface{}) bool
- func (f *Float) IsGreater(g interface{}) bool
- func (f *Float) IsGreaterOrEqual(g interface{}) bool
- func (f *Float) IsLess(g interface{}) bool
- func (f *Float) IsLessOrEqual(g interface{}) bool
- func (f *Float) IsZero() bool
- func (f *Float) MarshalJSON() ([]byte, error)
- func (f *Float) Mul(g interface{}) *Float
- func (f *Float) ParseFloat(s string) (err error)
- func (f *Float) Quo(g interface{}) *Float
- func (f *Float) String() string
- func (f *Float) Sub(g interface{}) *Float
- func (f *Float) UnmarshalJSON(in []byte) (err error)
- type Rat
- func (r *Rat) Add(g interface{}) *Rat
- func (r *Rat) Int64() int64
- func (r *Rat) IsEqual(g interface{}) bool
- func (r *Rat) IsGreater(g interface{}) bool
- func (r *Rat) IsGreaterOrEqual(g interface{}) bool
- func (r *Rat) IsGreaterThanZero() bool
- func (r *Rat) IsLess(g interface{}) bool
- func (r *Rat) IsLessOrEqual(g interface{}) bool
- func (r *Rat) IsLessThanZero() bool
- func (r *Rat) IsZero() bool
- func (r *Rat) MarshalJSON() ([]byte, error)
- func (r *Rat) Mul(g interface{}) *Rat
- func (r *Rat) Quo(g interface{}) *Rat
- func (r *Rat) Scan(src interface{}) error
- func (r *Rat) String() string
- func (r *Rat) Sub(g interface{}) *Rat
- func (r *Rat) UnmarshalJSON(in []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
var DefaultBitPrecision uint = 128
DefaultBitPrecision define the maximum number of mantissa bits available to represent the value.
In standard library this value is 24 for float32 or 53 for float64.
One should change this value before using the new extended Float in the program.
nolint: gochecknoglobals
var DefaultDigitPrecision = 8
DefaultDigitPrecision define the default number of digits after decimal point which affect the return of String() and MarshalJSON() methods.
A zero value of digit precision mean is it will use the default output of 'f' format.
One should change this value before using the new extended Float or Rat in the program.
nolint: gochecknoglobals
var DefaultRoundingMode = big.ToNearestAway
DefaultRoundingMode define the default rounding mode for all instance of Float.
One should change this value before using the new extended Float in the program.
nolint: gochecknoglobals
Functions ¶
This section is empty.
Types ¶
type Float ¶
Float extend the standard big.Float by setting each instance precision to DefaultBitPrecision, rounding mode to DefaultRoundingMode, and using DefaultDigitPrecision value after decimal point when converted to string.
func AddFloat ¶
func AddFloat(f, g interface{}) *Float
AddFloat return the rounded sum `f+g` and return f.
func CreateFloat ¶
Create Float with default bit precision and rounding mode.
func MulFloat ¶
func MulFloat(f, g interface{}) *Float
MulFloat return the result of multiplication `f*g`. It will return nil if `f` or `g` is not convertible to Float.
func MustParseFloat ¶
MustParseFloat convert the string `s` into Float or panic.
func NewFloat ¶
NewFloat create and initialize new Float with default bit precision, and rounding mode.
func ParseFloat ¶
ParseFloat the string s into Float value.
func QuoFloat ¶
func QuoFloat(f, g interface{}) *Float
QuoFloat return the quotient of `f/g` as new Float.
func (*Float) IsGreaterOrEqual ¶
IsGreaterOrEqual will return true if `f >= g`.
func (*Float) IsLessOrEqual ¶
IsLessOrEqual will return true if `f <= g`.
func (*Float) MarshalJSON ¶
MarshalJSON implement the json.Marshaler interface and return the output of String method.
func (*Float) Mul ¶
Mul sets f to product of `f * g` and return the result as f. If g is not convertible to Float it will return nil.
func (*Float) ParseFloat ¶
Parse the string into Float value.
func (*Float) Quo ¶
Quo sets f to quotient of `f/g` and return the result as f. If g is not convertible to Float it will return nil.
func (*Float) String ¶
String format the Float value into string with maximum mantissa is set by digit precision option.
Unlike standard String method, this method will trim trailing zero digit or decimal point at the end of mantissa.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON convert the JSON byte value into Float.
type Rat ¶
Rat extend the standard big.Rat using rounding mode ToZero.
func AddRat ¶
func AddRat(f ...interface{}) *Rat
AddRat return the sum of `f+g+...`. It will return nil if `f` or `g` is not convertable to Rat.
func MulRat ¶
func MulRat(f ...interface{}) *Rat
MulRat return the result of multiplication `f*...`. It will return nil if parameter is empty or `f` is not convertable to Rat.
func MustRat ¶
func MustRat(v interface{}) (r *Rat)
MustRat create and initialize new Rat value from v or panic if v is unknown type that cannot be converted to Rat.
func NewRat ¶
func NewRat(v interface{}) (r *Rat)
NewRat create and initialize new Rat value from v or nil if v is invalid type that cannot be converted to Rat.
func QuoRat ¶
func QuoRat(f ...interface{}) *Rat
QuoRat return the quotient of `f/g/...` as new Rat.
func SubRat ¶
func SubRat(f ...interface{}) *Rat
SubRat return the result of subtraction `f-g-...` as new Rat.
func (*Rat) IsGreaterOrEqual ¶
IsGreaterOrEqual will return true if `r >= g`.
func (*Rat) IsGreaterThanZero ¶
IsGreaterThanZero will return true if `r > 0`.
func (*Rat) IsLessOrEqual ¶
IsLessOrEqual will return true if `r <= g`.
func (*Rat) IsLessThanZero ¶
IsLessThanZero return true if `r < 0`.
func (*Rat) MarshalJSON ¶
MarshalJSON implement the json.Marshaler interface and return the output of String method.
func (*Rat) Mul ¶
Mul sets r to product of `r * g` and return the result as r. If g is not convertible to Rat it will return nil.
func (*Rat) Quo ¶
Quo sets r to quotient of `r/g` and return the result as r. If g is not convertible to Rat it will return nil.
func (*Rat) String ¶
String format the Rat value into string with maximum mantissa is set by digit precision option with rounding mode set to zero.
Unlike standard String method, this method will trim trailing zero digit or decimal point at the end of mantissa.
func (*Rat) UnmarshalJSON ¶
UnmarshalJSON convert the JSON byte value into Rat.