value

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("invalid value")

ErrInvalidValue is returned when an unexpected value is given to a NewAmount constructor.

View Source
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

func MustNewInt(v Int, err error) Int

MustNewInt returns Int if err is nil and panics otherwise.

func NewIntFromBigInt

func NewIntFromBigInt(i *big.Int) Int

NewIntFromBigInt sets the internal bigInt type to i.

func NewIntFromBytes

func NewIntFromBytes(b []byte) Int

NewIntFromBytes sets the internal bigInt type to the interpreted value of b.

func NewIntFromInt64

func NewIntFromInt64(v int64) Int

NewIntFromInt64 returns a new Int with the internal big.Int set to v.

func NewIntFromString

func NewIntFromString(s string) (Int, error)

NewIntFromString returns a new Int with the internal big.Int parsed from a string.

func NewIntFromUint64

func NewIntFromUint64(v uint64) Int

NewIntFromUint64 returns a new Int with the internal big.Int set to v.

func (Int) Add

func (v Int) Add(x Int) Int

Add returns the sum between v and x.

func (Int) BigInt

func (v Int) BigInt() *big.Int

BigInt returns the internal big.Int type.

func (Int) Bytes

func (v Int) Bytes() []byte

Bytes returns the absolute value of the internal big.Int as a big-endian byte slice.

func (Int) Div

func (v Int) Div(x Int) Int

Div returns the division between v and x.

func (Int) Int64

func (v Int) Int64() 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) IsEqual

func (v Int) IsEqual(x Int) bool

IsEqual compares v and x and returns true if v is equal to x.

func (Int) IsGreaterThan

func (v Int) IsGreaterThan(x Int) bool

IsGreaterThan compares v and x and returns true if v is greater than x.

func (Int) IsLesserThan

func (v Int) IsLesserThan(x Int) bool

IsLesserThan compares v and x and returns true if v is lesser than x.

func (Int) MarshalJSON

func (v Int) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int) MarshalText

func (v Int) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Int) Mul

func (v Int) Mul(x Int) Int

Mul returns the product between v and x.

func (Int) Neg

func (v Int) Neg() Int

Neg sets v.bigInt to -v.bigInt.

func (*Int) Scan

func (v *Int) Scan(value interface{}) error

Scan defines how the Int is read from the database.

func (*Int) SetBigInt

func (v *Int) SetBigInt(i *big.Int) Int

SetBigInt is a wrapper over (*big.Int).Set.. It sets the internal big.Int value to i.

func (*Int) SetBytes

func (v *Int) SetBytes(buf []byte) Int

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

func (v *Int) SetString(s string) (Int, bool)

SetString is a wrapper over (*big.Int).SetString. It interprets the s and returns a boolean indicating the operation success.

func (Int) String

func (v Int) String() string

String returns the decimal representation of the internal big.Int.

func (Int) Sub

func (v Int) Sub(x Int) Int

Sub returns the difference between v and x.

func (*Int) UnmarshalJSON

func (v *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int) UnmarshalText

func (v *Int) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Int) Value

func (v Int) Value() (driver.Value, error)

Value defines how the Int is stored in the database.

Directories

Path Synopsis
Package money implements an Amount type used to represent a monetary amount defined by the following properties:
Package money implements an Amount type used to represent a monetary amount defined by the following properties:

Jump to

Keyboard shortcuts

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