decimal

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinDecimal32Precision  = 1
	MaxDecimal32Precision  = 9
	MinDecimal64Precision  = 10
	MaxDecimal64Precision  = 18
	MinDecimal128Precision = 19
	MaxDecimal128Precision = 38
	MinDecimal256Precision = 39
	MaxDecimal256Precision = 76
)

Variables

View Source
var (
	ErrScaleOverflow      = errors.New("decimal: scale overflow")
	ErrScaleUnderflow     = errors.New("decimal: scale underflow")
	ErrPrecisionOverflow  = errors.New("decimal: precision overflow")
	ErrPrecisionUnderflow = errors.New("decimal: precision underflow")
	ErrInvalidFloat64     = errors.New("decimal: invalid float64 number")
	ErrInvalidDecimal     = errors.New("decimal: invalid decimal number")
)
View Source
var Decimal128Zero = Decimal128{ZeroInt128, 0}
View Source
var Decimal256Zero = Decimal256{ZeroInt256, 0}
View Source
var Decimal32Zero = Decimal32{0, 0}
View Source
var Decimal64Zero = Decimal64{0, 0}

Functions

func EqualScaleDecimal128

func EqualScaleDecimal128(a, b Decimal128) (Decimal128, Decimal128)

func EqualScaleDecimal256

func EqualScaleDecimal256(a, b Decimal256) (Decimal256, Decimal256)

func EqualScaleDecimal32

func EqualScaleDecimal32(a, b Decimal32) (Decimal32, Decimal32)

func EqualScaleDecimal64

func EqualScaleDecimal64(a, b Decimal64) (Decimal64, Decimal64)

Types

type Decimal128

type Decimal128 struct {
	// contains filtered or unexported fields
}

38 digits

func NewDecimal128

func NewDecimal128(val Int128, scale int) Decimal128

func ParseDecimal128

func ParseDecimal128(s string) (Decimal128, error)

func (Decimal128) Add

func (d Decimal128) Add(value Decimal128) Decimal128

func (Decimal128) Add64

func (d Decimal128) Add64(value int64) Decimal128

func (Decimal128) Check

func (d Decimal128) Check() (bool, error)

func (Decimal128) Clone

func (d Decimal128) Clone() Decimal128

func (Decimal128) Cmp

func (a Decimal128) Cmp(b Decimal128) int

func (Decimal128) Eq

func (a Decimal128) Eq(b Decimal128) bool

func (Decimal128) Float64

func (d Decimal128) Float64() float64

func (Decimal128) Gt

func (a Decimal128) Gt(b Decimal128) bool

func (Decimal128) Gte

func (a Decimal128) Gte(b Decimal128) bool

func (Decimal128) Int128

func (d Decimal128) Int128() Int128

func (Decimal128) Int256

func (d Decimal128) Int256() Int256

func (Decimal128) Int64

func (d Decimal128) Int64() int64

func (Decimal128) IsValid

func (d Decimal128) IsValid() bool

func (Decimal128) IsZero

func (d Decimal128) IsZero() bool

func (Decimal128) Lt

func (a Decimal128) Lt(b Decimal128) bool

func (Decimal128) Lte

func (a Decimal128) Lte(b Decimal128) bool

func (Decimal128) MarshalText

func (d Decimal128) MarshalText() ([]byte, error)

func (Decimal128) Precision

func (d Decimal128) Precision() int

func (Decimal128) Quantize

func (d Decimal128) Quantize(scale int) Decimal128

func (Decimal128) RoundToInt64

func (d Decimal128) RoundToInt64() int64

func (Decimal128) Scale

func (d Decimal128) Scale() int

func (*Decimal128) Set

func (d *Decimal128) Set(value Int128)

func (*Decimal128) SetFloat64

func (d *Decimal128) SetFloat64(value float64, scale int) error

func (*Decimal128) SetInt128

func (d *Decimal128) SetInt128(value Int128, scale int) error

func (*Decimal128) SetInt64

func (d *Decimal128) SetInt64(value int64, scale int) error

func (*Decimal128) SetScale

func (d *Decimal128) SetScale(scale int)

func (Decimal128) String

func (d Decimal128) String() string

func (*Decimal128) UnmarshalText

func (d *Decimal128) UnmarshalText(buf []byte) error

type Decimal128Slice

type Decimal128Slice struct {
	Int128 []Int128
	Scale  int
}

type Decimal256

type Decimal256 struct {
	// contains filtered or unexported fields
}

76 digits

func NewDecimal256

func NewDecimal256(val Int256, scale int) Decimal256

func ParseDecimal256

func ParseDecimal256(s string) (Decimal256, error)

func (Decimal256) Add

func (d Decimal256) Add(value Decimal256) Decimal256

func (Decimal256) Add64

func (d Decimal256) Add64(value int64) Decimal256

func (Decimal256) Check

func (d Decimal256) Check() (bool, error)

func (Decimal256) Clone

func (d Decimal256) Clone() Decimal256

func (Decimal256) Cmp

func (a Decimal256) Cmp(b Decimal256) int

func (Decimal256) Eq

func (a Decimal256) Eq(b Decimal256) bool

func (Decimal256) Float64

func (d Decimal256) Float64() float64

func (Decimal256) Gt

func (a Decimal256) Gt(b Decimal256) bool

func (Decimal256) Gte

func (a Decimal256) Gte(b Decimal256) bool

func (Decimal256) Int128

func (d Decimal256) Int128() Int128

func (Decimal256) Int256

func (d Decimal256) Int256() Int256

func (Decimal256) Int64

func (d Decimal256) Int64() int64

func (Decimal256) IsValid

func (d Decimal256) IsValid() bool

func (Decimal256) IsZero

func (d Decimal256) IsZero() bool

func (Decimal256) Lt

func (a Decimal256) Lt(b Decimal256) bool

func (Decimal256) Lte

func (a Decimal256) Lte(b Decimal256) bool

func (Decimal256) MarshalText

func (d Decimal256) MarshalText() ([]byte, error)

func (Decimal256) Precision

func (d Decimal256) Precision() int

func (Decimal256) Quantize

func (d Decimal256) Quantize(scale int) Decimal256

func (Decimal256) RoundToInt64

func (d Decimal256) RoundToInt64() int64

func (Decimal256) Scale

func (d Decimal256) Scale() int

func (*Decimal256) Set

func (d *Decimal256) Set(value Int256)

func (*Decimal256) SetFloat64

func (d *Decimal256) SetFloat64(value float64, scale int) error

func (*Decimal256) SetInt128

func (d *Decimal256) SetInt128(value Int128, scale int) error

func (*Decimal256) SetInt256

func (d *Decimal256) SetInt256(value Int256, scale int) error

func (*Decimal256) SetInt64

func (d *Decimal256) SetInt64(value int64, scale int) error

func (*Decimal256) SetScale

func (d *Decimal256) SetScale(scale int)

func (Decimal256) String

func (d Decimal256) String() string

func (*Decimal256) UnmarshalText

func (d *Decimal256) UnmarshalText(buf []byte) error

type Decimal256Slice

type Decimal256Slice struct {
	Int256 []Int256
	Scale  int
}

type Decimal32

type Decimal32 struct {
	// contains filtered or unexported fields
}

9 digits

func NewDecimal32

func NewDecimal32(val int32, scale int) Decimal32

func ParseDecimal32

func ParseDecimal32(s string) (Decimal32, error)

func (Decimal32) Add

func (d Decimal32) Add(value Decimal32) Decimal32

func (Decimal32) Add64

func (d Decimal32) Add64(value int64) Decimal32

func (Decimal32) Check

func (d Decimal32) Check() (bool, error)

func (Decimal32) Clone

func (d Decimal32) Clone() Decimal32

func (Decimal32) Cmp

func (a Decimal32) Cmp(b Decimal32) int

func (Decimal32) Eq

func (a Decimal32) Eq(b Decimal32) bool

func (Decimal32) Float64

func (d Decimal32) Float64() float64

func (Decimal32) Gt

func (a Decimal32) Gt(b Decimal32) bool

func (Decimal32) Gte

func (a Decimal32) Gte(b Decimal32) bool

func (Decimal32) Int128

func (d Decimal32) Int128() Int128

func (Decimal32) Int256

func (d Decimal32) Int256() Int256

func (Decimal32) Int32

func (d Decimal32) Int32() int32

func (Decimal32) Int64

func (d Decimal32) Int64() int64

func (Decimal32) IsValid

func (d Decimal32) IsValid() bool

func (Decimal32) IsZero

func (d Decimal32) IsZero() bool

func (Decimal32) Lt

func (a Decimal32) Lt(b Decimal32) bool

func (Decimal32) Lte

func (a Decimal32) Lte(b Decimal32) bool

func (Decimal32) MarshalText

func (d Decimal32) MarshalText() ([]byte, error)

func (Decimal32) Precision

func (d Decimal32) Precision() int

func (Decimal32) Quantize

func (d Decimal32) Quantize(scale int) Decimal32

func (Decimal32) RoundToInt64

func (d Decimal32) RoundToInt64() int64

func (Decimal32) Scale

func (d Decimal32) Scale() int

func (*Decimal32) Set

func (d *Decimal32) Set(value int32)

func (*Decimal32) SetFloat64

func (d *Decimal32) SetFloat64(value float64, scale int) error

func (*Decimal32) SetInt64

func (d *Decimal32) SetInt64(value int64, scale int) error

func (*Decimal32) SetScale

func (d *Decimal32) SetScale(scale int)

func (Decimal32) String

func (d Decimal32) String() string

func (*Decimal32) UnmarshalText

func (d *Decimal32) UnmarshalText(buf []byte) error

type Decimal32Slice

type Decimal32Slice struct {
	Int32 []int32
	Scale int
}

type Decimal64

type Decimal64 struct {
	// contains filtered or unexported fields
}

18 digits

func NewDecimal64

func NewDecimal64(val int64, scale int) Decimal64

func ParseDecimal64

func ParseDecimal64(s string) (Decimal64, error)

func (Decimal64) Add

func (d Decimal64) Add(value Decimal64) Decimal64

func (Decimal64) Add64

func (d Decimal64) Add64(value int64) Decimal64

func (Decimal64) Check

func (d Decimal64) Check() (bool, error)

func (Decimal64) Clone

func (d Decimal64) Clone() Decimal64

func (Decimal64) Cmp

func (a Decimal64) Cmp(b Decimal64) int

func (Decimal64) Eq

func (a Decimal64) Eq(b Decimal64) bool

func (Decimal64) Float64

func (d Decimal64) Float64() float64

func (Decimal64) Gt

func (a Decimal64) Gt(b Decimal64) bool

func (Decimal64) Gte

func (a Decimal64) Gte(b Decimal64) bool

func (Decimal64) Int128

func (d Decimal64) Int128() Int128

func (Decimal64) Int256

func (d Decimal64) Int256() Int256

func (Decimal64) Int64

func (d Decimal64) Int64() int64

func (Decimal64) IsValid

func (d Decimal64) IsValid() bool

func (Decimal64) IsZero

func (d Decimal64) IsZero() bool

func (Decimal64) Lt

func (a Decimal64) Lt(b Decimal64) bool

func (Decimal64) Lte

func (a Decimal64) Lte(b Decimal64) bool

func (Decimal64) MarshalText

func (d Decimal64) MarshalText() ([]byte, error)

func (Decimal64) Precision

func (d Decimal64) Precision() int

func (Decimal64) Quantize

func (d Decimal64) Quantize(scale int) Decimal64

func (Decimal64) RoundToInt64

func (d Decimal64) RoundToInt64() int64

func (Decimal64) Scale

func (d Decimal64) Scale() int

func (*Decimal64) Set

func (d *Decimal64) Set(value int64)

func (*Decimal64) SetFloat64

func (d *Decimal64) SetFloat64(value float64, scale int) error

func (*Decimal64) SetInt64

func (d *Decimal64) SetInt64(value int64, scale int) error

func (*Decimal64) SetScale

func (d *Decimal64) SetScale(scale int)

func (Decimal64) String

func (d Decimal64) String() string

func (*Decimal64) UnmarshalText

func (d *Decimal64) UnmarshalText(buf []byte) error

type Decimal64Slice

type Decimal64Slice struct {
	Int64 []int64
	Scale int
}

Jump to

Keyboard shortcuts

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