fractions

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OneHundredPercent = Percent{
	Fraction: *NewFraction(big.NewInt(constants.NHUNDRED), big.NewInt(1)),
	// contains filtered or unexported fields
}

Functions

This section is empty.

Types

type CurrencyAmount

type CurrencyAmount struct {
	Fraction
	entities.Currency
}

func NewCurrencyAmount

func NewCurrencyAmount(currency *entities.Currency, amount *big.Int) *CurrencyAmount

func (*CurrencyAmount) Add

func (ca *CurrencyAmount) Add(other *CurrencyAmount) *CurrencyAmount

func (*CurrencyAmount) Raw

func (ca *CurrencyAmount) Raw() *big.Int

func (*CurrencyAmount) Subtract

func (ca *CurrencyAmount) Subtract(other *CurrencyAmount) *CurrencyAmount

func (*CurrencyAmount) ToExact

func (ca *CurrencyAmount) ToExact(format interface{}) string

func (*CurrencyAmount) ToFixed

func (ca *CurrencyAmount) ToFixed(decimalPlaces int, format interface{}, rounding big.RoundingMode) string

func (*CurrencyAmount) ToSignificant

func (ca *CurrencyAmount) ToSignificant(significantDigits int, format interface{}, rounding Rounding) string

type Fraction

type Fraction struct {
	Numerator   *big.Int `json:"numerator,omitempty"`
	Denominator *big.Int `json:"denominator,omitempty"`
}

func NewFraction

func NewFraction(numerator, denominator *big.Int) *Fraction

func (*Fraction) Add

func (f *Fraction) Add(other *Fraction) *Fraction

func (*Fraction) AsDecimal

func (f *Fraction) AsDecimal() decimal.Decimal

func (*Fraction) AsFraction

func (f *Fraction) AsFraction() *Fraction

func (*Fraction) Divide

func (f *Fraction) Divide(other *Fraction) *Fraction

func (*Fraction) EqualTo

func (f *Fraction) EqualTo(other *Fraction) bool

func (*Fraction) GreaterThan

func (f *Fraction) GreaterThan(other *Fraction) bool

func (*Fraction) Invert

func (f *Fraction) Invert() *Fraction

func (*Fraction) LessThan

func (f *Fraction) LessThan(other *Fraction) bool

func (*Fraction) Multiply

func (f *Fraction) Multiply(other *Fraction) *Fraction

func (*Fraction) Quotient

func (f *Fraction) Quotient() *big.Int

func (*Fraction) Remainder

func (f *Fraction) Remainder() *Fraction

func (*Fraction) Subtract

func (f *Fraction) Subtract(other *Fraction) *Fraction

func (*Fraction) ToFixed

func (f *Fraction) ToFixed(decimalPlaces int, format interface{}, rounding big.RoundingMode) string

func (*Fraction) ToSignificant

func (f *Fraction) ToSignificant(significantDigits int, format interface{}, rounding Rounding) string

type Percent

type Percent struct {
	Fraction
	// contains filtered or unexported fields
}

func ToPercent

func ToPercent(fraction *Fraction) *Percent

func (*Percent) Add

func (p *Percent) Add(other *Percent) *Percent

func (*Percent) Divide

func (p *Percent) Divide(other *Percent) *Percent

func (*Percent) Multiply

func (p *Percent) Multiply(other *Percent) *Percent

func (*Percent) Subtract

func (p *Percent) Subtract(other *Percent) *Percent

func (*Percent) ToFixed

func (p *Percent) ToFixed(decimalPlaces int, format interface{}, rounding big.RoundingMode) string

func (*Percent) ToSignificant

func (p *Percent) ToSignificant(significantDigits int, format interface{}, rounding Rounding) string

type Price

type Price struct {
	Fraction
	BaseCurrency  entities.Currency `json:"base_currency,omitempty"`
	QuoteCurrency entities.Currency `json:"quote_currency,omitempty"`
	Scalar        Fraction          `json:"scalar,omitempty"`
}

func NewPrice

func NewPrice(baseCurrency, quoteCurrency *entities.Currency, denominator, numerator *big.Int) *Price

func (*Price) Adjusted

func (p *Price) Adjusted() *Fraction

func (*Price) AdjustedForDecimals

func (p *Price) AdjustedForDecimals() *Fraction

func (*Price) Invert

func (p *Price) Invert() *Price

func (*Price) Multiply

func (p *Price) Multiply(other *Price) *Price

func (*Price) Quote

func (p *Price) Quote(currencyAmount CurrencyAmount) *CurrencyAmount

func (*Price) Raw

func (p *Price) Raw() *Fraction

func (*Price) ToFixed

func (p *Price) ToFixed(decimalPlaces int, format interface{}, rounding big.RoundingMode) string

func (*Price) ToSignificant

func (p *Price) ToSignificant(significantDigits int, format interface{}, rounding Rounding) string

type Rounding

type Rounding int
const (
	RoundDown Rounding = iota
	RoundHalfUp
	RoundUp
)

type TokenAmount

type TokenAmount struct {
	Fraction
	entities.Token
}

func NewTokenAmount

func NewTokenAmount(token entities.Token, amount *big.Int) *TokenAmount

func (*TokenAmount) Add

func (ta *TokenAmount) Add(other *TokenAmount) *TokenAmount

func (*TokenAmount) AsCurrencyAmount

func (ta *TokenAmount) AsCurrencyAmount() *CurrencyAmount

func (*TokenAmount) Raw

func (ta *TokenAmount) Raw() *big.Int

func (*TokenAmount) Subtract

func (ta *TokenAmount) Subtract(other *TokenAmount) *TokenAmount

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL