Documentation ¶
Overview ¶
Package math provides helper functions for doing mathematical calculations and parsing for the ecocredit module.
Index ¶
- type Dec
- func (x Dec) Add(y Dec) (Dec, error)
- func (x Dec) Cmp(y Dec) int
- func (x Dec) Int64() (int64, error)
- func (x Dec) IsEqual(y Dec) bool
- func (x Dec) IsNegative() bool
- func (x Dec) IsPositive() bool
- func (x Dec) IsZero() bool
- func (x Dec) Quo(y Dec) (Dec, error)
- func (x Dec) String() string
- func (x Dec) Sub(y Dec) (Dec, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dec ¶
type Dec struct {
// contains filtered or unexported fields
}
Dec is a wrapper struct around apd.Decimal that does no mutation of apd.Decimal's when performing arithmetic, instead creating a new apd.Decimal for every operation ensuring usage is safe.
Using apd.Decimal directly can be unsafe because apd operations mutate the underlying Decimal, but when copying the big.Int structure can be shared between Decimal instances causing corruption. This was originally discovered in regen0-network/mainnet#15.
func NewDecFromInt64 ¶
func NewDecFromString ¶
func SubNonNegative ¶
SubNonNegative subtracts the value of y from x and returns the result with arbitrary precision. Returns an error if the result is negative.
func (Dec) Add ¶
Add returns a new Dec with value `x+y` without mutating any argument and error if there is an overflow.