Documentation ¶
Index ¶
- Variables
- func MaxPrecision[T DecimalTypes]() int
- type Decimal128
- type Decimal256
- type Decimal32
- func (n Decimal32) Abs() Decimal32
- func (d Decimal32) Add(rhs Decimal32) Decimal32
- func (n Decimal32) Cmp(other Decimal32) int
- func (d Decimal32) Div(rhs Decimal32) (res, rem Decimal32)
- func (n Decimal32) FitsInPrecision(prec int32) bool
- func (n Decimal32) IncreaseScaleBy(increase int32) Decimal32
- func (d Decimal32) Mul(rhs Decimal32) Decimal32
- func (d Decimal32) Negate() Decimal32
- func (d Decimal32) Pow(rhs Decimal32) Decimal32
- func (n Decimal32) ReduceScaleBy(reduce int32, round bool) Decimal32
- func (n Decimal32) Rescale(originalScale, newScale int32) (out Decimal32, err error)
- func (d Decimal32) Sign() int
- func (d Decimal32) Sub(rhs Decimal32) Decimal32
- func (n Decimal32) ToBigFloat(scale int32) *big.Float
- func (n Decimal32) ToFloat32(scale int32) float32
- func (n Decimal32) ToFloat64(scale int32) float64
- func (n Decimal32) ToString(scale int32) string
- type Decimal64
- func (n Decimal64) Abs() Decimal64
- func (d Decimal64) Add(rhs Decimal64) Decimal64
- func (n Decimal64) Cmp(other Decimal64) int
- func (d Decimal64) Div(rhs Decimal64) (res, rem Decimal64)
- func (n Decimal64) FitsInPrecision(prec int32) bool
- func (n Decimal64) IncreaseScaleBy(increase int32) Decimal64
- func (d Decimal64) Mul(rhs Decimal64) Decimal64
- func (d Decimal64) Negate() Decimal64
- func (d Decimal64) Pow(rhs Decimal64) Decimal64
- func (n Decimal64) ReduceScaleBy(reduce int32, round bool) Decimal64
- func (n Decimal64) Rescale(originalScale, newScale int32) (out Decimal64, err error)
- func (d Decimal64) Sign() int
- func (d Decimal64) Sub(rhs Decimal64) Decimal64
- func (n Decimal64) ToBigFloat(scale int32) *big.Float
- func (n Decimal64) ToFloat32(scale int32) float32
- func (n Decimal64) ToFloat64(scale int32) float64
- func (n Decimal64) ToString(scale int32) string
- type DecimalTypes
- type Num
- type Traits
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Dec32Traits dec32Traits Dec64Traits dec64Traits Dec128Traits dec128Traits Dec256Traits dec256Traits )
Functions ¶
func MaxPrecision ¶
func MaxPrecision[T DecimalTypes]() int
Types ¶
type Decimal128 ¶
type Decimal128 = decimal128.Num
func Decimal128FromFloat ¶
func Decimal128FromFloat(v float64, prec, scale int32) (Decimal128, error)
func Decimal128FromString ¶
func Decimal128FromString(v string, prec, scale int32) (n Decimal128, err error)
type Decimal256 ¶
type Decimal256 = decimal256.Num
func Decimal256FromFloat ¶
func Decimal256FromFloat(v float64, prec, scale int32) (Decimal256, error)
func Decimal256FromString ¶
func Decimal256FromString(v string, prec, scale int32) (n Decimal256, err error)
type Decimal32 ¶
type Decimal32 int32
func Decimal32FromFloat ¶
func Decimal32FromString ¶
func (Decimal32) FitsInPrecision ¶
func (Decimal32) IncreaseScaleBy ¶
func (Decimal32) ReduceScaleBy ¶
type Decimal64 ¶
type Decimal64 int64
func Decimal64FromFloat ¶
func Decimal64FromString ¶
func (Decimal64) FitsInPrecision ¶
func (Decimal64) IncreaseScaleBy ¶
func (Decimal64) ReduceScaleBy ¶
type DecimalTypes ¶
type DecimalTypes interface { Decimal32 | Decimal64 | Decimal128 | Decimal256 }
DecimalTypes is a generic constraint representing the implemented decimal types in this package, and a single point of update for future additions. Everything else is constrained by this.
type Num ¶
type Num[T DecimalTypes] interface { Negate() T Add(T) T Sub(T) T Mul(T) T Div(T) (res, rem T) Pow(T) T FitsInPrecision(int32) bool Abs() T Sign() int Rescale(int32, int32) (T, error) Cmp(T) int IncreaseScaleBy(int32) T ReduceScaleBy(int32, bool) T ToFloat32(int32) float32 ToFloat64(int32) float64 ToBigFloat(int32) *big.Float ToString(int32) string }
Num is an interface that is useful for building generic types for all decimal type implementations. It presents all the methods and interfaces necessary to operate on the decimal objects without having to care about the bit width.
type Traits ¶
type Traits[T DecimalTypes] interface { BytesRequired(int) int FromString(string, int32, int32) (T, error) FromFloat64(float64, int32, int32) (T, error) }
Traits is a convenience for building generic objects for operating on Decimal values to get around the limitations of Go generics. By providing this interface a generic object can handle producing the proper types to generate new decimal values.
Click to show internal directories.
Click to hide internal directories.