Documentation ¶
Overview ¶
Package math provides helper functions for doing mathematical calculations and parsing for the ecocredit module.
Index ¶
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.