Documentation
¶
Overview ¶
Package math includes important helpers for Ethereum such as fast integer square roots.
Index ¶
- Variables
- func Add64(a, b uint64) (uint64, error)
- func AddInt(i ...int) (int, error)
- func CachedSquareRoot(balance uint64) uint64
- func CeilDiv8(n int) int
- func Div64(a, b uint64) (uint64, error)
- func Int(u uint64) (int, error)
- func IntegerSquareRoot(n uint64) uint64
- func IsPowerOf2(n uint64) bool
- func IsValidUint256(bi *big.Int) bool
- func Mod64(a, b uint64) (uint64, error)
- func Mul64(a, b uint64) (uint64, error)
- func PowerOf2(n uint64) uint64
- func Sub64(a, b uint64) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrOverflow = errors.New("integer overflow") ErrDivByZero = errors.New("integer divide by zero") ErrMulOverflow = errors.New("multiplication overflows") ErrAddOverflow = errors.New("addition overflows") ErrSubUnderflow = errors.New("subtraction underflow") )
ErrOverflow occurs when an operation exceeds max or minimum values.
Functions ¶
func Add64 ¶
Add64 adds 2 64-bit unsigned integers and checks if they lead to an overflow. If they do not, it returns the result without an error.
func CachedSquareRoot ¶
CachedSquareRoot implements Newton's algorithm to compute the square root of the given uint64 starting from the last cached value
func Int ¶
Int returns the integer value of the uint64 argument. If there is an overflow, then an error is returned.
func IntegerSquareRoot ¶
IntegerSquareRoot defines a function that returns the largest possible integer root of a number using go's standard library.
func IsPowerOf2 ¶
IsPowerOf2 returns true if n is an exact power of two. False otherwise.
func IsValidUint256 ¶
IsValidUint256 given a bigint checks if the value is a valid Uint256
func Mod64 ¶
Mod64 finds remainder of division of two 64-bit unsigned integers and checks for errors.
func Mul64 ¶
Mul64 multiples 2 64-bit unsigned integers and checks if they lead to an overflow. If they do not, it returns the result without an error.
Types ¶
This section is empty.