package math
import "github.com/ethereum/go-ethereum/common/math"
Package math provides integer math utilities.
Index ¶
- Variables
- func BigPow(a, b int64) *big.Int
- func MustParseBig256(s string) *big.Int
- func MustParseUint64(s string) uint64
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ParseBig256(s string) (*big.Int, bool)
- func ParseUint64(s string) (uint64, bool)
- func ReadBits(bigint *big.Int, buf []byte)
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func SafeSub(x, y uint64) (uint64, bool)
- func U256(x *big.Int) *big.Int
- func U256Bytes(n *big.Int) []byte
- type Decimal256
- func NewDecimal256(x int64) *Decimal256
- func (i *Decimal256) MarshalText() ([]byte, error)
- func (i *Decimal256) String() string
- func (i *Decimal256) UnmarshalText(input []byte) error
- type HexOrDecimal256
- func NewHexOrDecimal256(x int64) *HexOrDecimal256
- func (i *HexOrDecimal256) MarshalText() ([]byte, error)
- func (i *HexOrDecimal256) UnmarshalJSON(input []byte) error
- func (i *HexOrDecimal256) UnmarshalText(input []byte) error
- type HexOrDecimal64
Variables ¶
Various big integer limit values.
Functions ¶
func BigPow ¶
BigPow returns a ** b as a big integer.
func MustParseBig256 ¶
MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
func MustParseUint64 ¶
MustParseUint64 parses s as an integer and panics if the string is invalid.
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ParseBig256 ¶
ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
func ParseUint64 ¶
ParseUint64 parses s as an integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
func ReadBits ¶
ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.
func SafeAdd ¶
SafeAdd returns x+y and checks for overflow.
func SafeMul ¶
SafeMul returns x*y and checks for overflow.
func SafeSub ¶
SafeSub returns x-y and checks for overflow.
func U256 ¶
U256 encodes x as a 256 bit two's complement number. This operation is destructive.
func U256Bytes ¶
U256Bytes converts a big Int into a 256bit EVM number. This operation is destructive.
Types ¶
type Decimal256 ¶
Decimal256 unmarshals big.Int as a decimal string. When unmarshalling, it however accepts either "0x"-prefixed (hex encoded) or non-prefixed (decimal)
func NewDecimal256 ¶
func NewDecimal256(x int64) *Decimal256
NewDecimal256 creates a new Decimal256
func (*Decimal256) MarshalText ¶
func (i *Decimal256) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*Decimal256) String ¶
func (i *Decimal256) String() string
String implements Stringer.
func (*Decimal256) UnmarshalText ¶
func (i *Decimal256) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type HexOrDecimal256 ¶
HexOrDecimal256 marshals big.Int as hex or decimal.
func NewHexOrDecimal256 ¶
func NewHexOrDecimal256(x int64) *HexOrDecimal256
NewHexOrDecimal256 creates a new HexOrDecimal256
func (*HexOrDecimal256) MarshalText ¶
func (i *HexOrDecimal256) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*HexOrDecimal256) UnmarshalJSON ¶
func (i *HexOrDecimal256) UnmarshalJSON(input []byte) error
UnmarshalJSON implements json.Unmarshaler.
It is similar to UnmarshalText, but allows parsing real decimals too, not just quoted decimal strings.
func (*HexOrDecimal256) UnmarshalText ¶
func (i *HexOrDecimal256) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type HexOrDecimal64 ¶
type HexOrDecimal64 uint64
HexOrDecimal64 marshals uint64 as hex or decimal.
func (HexOrDecimal64) MarshalText ¶
func (i HexOrDecimal64) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*HexOrDecimal64) UnmarshalJSON ¶
func (i *HexOrDecimal64) UnmarshalJSON(input []byte) error
UnmarshalJSON implements json.Unmarshaler.
It is similar to UnmarshalText, but allows parsing real decimals too, not just quoted decimal strings.
func (*HexOrDecimal64) UnmarshalText ¶
func (i *HexOrDecimal64) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
Source Files ¶
- Version
- v1.16.1 (latest)
- Published
- Jul 2, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 5 days ago –
Tools for package owners.