Documentation ¶
Index ¶
- Constants
- func As[T fixed.Dx, TO xmath.Numeric](f Int[T]) TO
- func CheckedAs[T fixed.Dx, TO xmath.Numeric](f Int[T]) (TO, error)
- func MaxDecimalDigits[T fixed.Dx]() int
- func Multiplier[T fixed.Dx]() int64
- type Fraction
- type Int
- func (f Int[T]) Abs() Int[T]
- func (f Int[T]) Ceil() Int[T]
- func (f Int[T]) Comma() string
- func (f Int[T]) CommaWithSign() string
- func (f Int[T]) Dec() Int[T]
- func (f Int[T]) Div(value Int[T]) Int[T]
- func (f Int[T]) Inc() Int[T]
- func (f Int[T]) MarshalJSON() ([]byte, error)
- func (f Int[T]) MarshalText() ([]byte, error)
- func (f Int[T]) MarshalYAML() (any, error)
- func (f Int[T]) Max(value Int[T]) Int[T]
- func (f Int[T]) Min(value Int[T]) Int[T]
- func (f Int[T]) Mod(value Int[T]) Int[T]
- func (f Int[T]) Mul(value Int[T]) Int[T]
- func (f Int[T]) Round() Int[T]
- func (f Int[T]) String() string
- func (f Int[T]) StringWithSign() string
- func (f Int[T]) Trunc() Int[T]
- func (f *Int[T]) UnmarshalJSON(in []byte) error
- func (f *Int[T]) UnmarshalText(text []byte) error
- func (f *Int[T]) UnmarshalYAML(unmarshal func(any) error) error
Constants ¶
const ( // Max holds the maximum value. Max = math.MaxInt64 // Min holds the minimum value. Min = math.MinInt64 )
Variables ¶
This section is empty.
Functions ¶
func CheckedAs ¶
CheckedAs is the same as As(), except that it returns an error if the value cannot be represented exactly in the requested destination type.
func MaxDecimalDigits ¶
MaxDecimalDigits returns the maximum number of digits after the decimal that will be used.
Types ¶
type Fraction ¶ added in v1.71.0
Fraction holds a fractional value.
func NewFraction ¶ added in v1.71.0
NewFraction creates a new fractional value from a string.
func (Fraction[T]) MarshalJSON ¶ added in v1.71.0
MarshalJSON implements json.Marshaler.
func (*Fraction[T]) Normalize ¶ added in v1.71.0
func (f *Fraction[T]) Normalize()
Normalize the fraction, eliminating any division by zero and ensuring a positive denominator.
func (Fraction[T]) StringWithSign ¶ added in v1.71.0
StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive.
func (*Fraction[T]) UnmarshalJSON ¶ added in v1.71.0
UnmarshalJSON implements json.Unmarshaler.
type Int ¶
Int holds a fixed-point value. Values are truncated, not rounded. Values can be added and subtracted directly. For multiplication and division, the provided Mul() and Div() methods should be used.
func FromString ¶
FromString creates a new value from a string.
func FromStringForced ¶
FromStringForced creates a new value from a string.
func MaxSafeMultiply ¶
MaxSafeMultiply returns the maximum value that can be safely multiplied without overflow.
func (Int[T]) Comma ¶
Comma returns the same as String(), but with commas for values of 1000 and greater.
func (Int[T]) CommaWithSign ¶
CommaWithSign returns the same as Comma(), but prefixes the value with a '+' if it is positive
func (Int[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Int[T]) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Int[T]) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (Int[T]) Mod ¶
Mod returns the remainder after subtracting all full multiples of the passed-in value.
func (Int[T]) StringWithSign ¶
StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive
func (Int[T]) Trunc ¶
Trunc returns a new value which has everything to the right of the decimal place truncated.
func (*Int[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Int[T]) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.