Documentation ¶
Overview ¶
Package value implements big numbers types that are used to store, persist and represents large integer values.
! Operations with these numbers should be done with the math/big package.
Index ¶
- Variables
- type Int
- func (v Int) Add(x Int) Int
- func (v Int) BigInt() *big.Int
- func (v Int) Bytes() []byte
- func (v Int) Div(x Int) Int
- func (v Int) Int64() int64
- func (v Int) IsEqual(x Int) bool
- func (v Int) IsGreaterThan(x Int) bool
- func (v Int) IsLesserThan(x Int) bool
- func (v Int) MarshalJSON() ([]byte, error)
- func (v Int) MarshalText() ([]byte, error)
- func (v Int) Mul(x Int) Int
- func (v Int) Neg() Int
- func (v *Int) Scan(value interface{}) error
- func (v *Int) SetBigInt(i *big.Int) Int
- func (v *Int) SetBytes(buf []byte) Int
- func (v *Int) SetString(s string) (Int, bool)
- func (v Int) String() string
- func (v Int) Sub(x Int) Int
- func (v *Int) UnmarshalJSON(data []byte) error
- func (v *Int) UnmarshalText(text []byte) error
- func (v Int) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidValue = errors.New("invalid value")
ErrInvalidValue is returned when an unexpected value is given to a NewAmount constructor.
var ZeroInt = Int{}
ZeroInt has the `valid` property set to true.
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int represents an integer
! This is intended to be used for storage and representation rather than for the big.Int behavior. It supports basic operations like add, sub, mul and div, but it's recommended to work with the `big` library.
func MustNewInt ¶
MustNewInt returns Int if err is nil and panics otherwise.
func NewIntFromBigInt ¶
NewIntFromBigInt sets the internal bigInt type to i.
func NewIntFromBytes ¶
NewIntFromBytes sets the internal bigInt type to the interpreted value of b.
func NewIntFromInt64 ¶
NewIntFromInt64 returns a new Int with the internal big.Int set to v.
func NewIntFromString ¶
NewIntFromString returns a new Int with the internal big.Int parsed from a string.
func NewIntFromUint64 ¶
NewIntFromUint64 returns a new Int with the internal big.Int set to v.
func (Int) Bytes ¶
Bytes returns the absolute value of the internal big.Int as a big-endian byte slice.
func (Int) Int64 ¶
Int64 it's a wrapper over (*big.Int).Int64.
It returns the int64 representation of x. If x cannot be represented in an int64, the result is undefined.
func (Int) IsGreaterThan ¶
IsGreaterThan compares v and x and returns true if v is greater than x.
func (Int) IsLesserThan ¶
IsLesserThan compares v and x and returns true if v is lesser than x.
func (Int) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Int) SetBigInt ¶
SetBigInt is a wrapper over (*big.Int).Set.. It sets the internal big.Int value to i.
func (*Int) SetBytes ¶
SetBytes is a wrapper over (*big.Int).SetBytes.
It interprets buf as the bytes of a big-endian unsigned integer, sets v.bigInt to that value, and returns v.
func (*Int) SetString ¶
SetString is a wrapper over (*big.Int).SetString. It interprets the s and returns a boolean indicating the operation success.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Int) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.