Documentation
¶
Overview ¶
Package math provides safe arithmetic operations for the DEX VM.
Index ¶
- Variables
- func AbsDiffU64(a, b uint64) uint64
- func BigMulDiv(a, b, c *big.Int) *big.Int
- func BigMulDivRoundUp(a, b, c *big.Int) *big.Int
- func CheckAddOverflowU64(a, b uint64) bool
- func CheckMulOverflowU64(a, b uint64) bool
- func ClampU64(value, min, max uint64) uint64
- func MaxU64(a, b uint64) uint64
- func MinU64(a, b uint64) uint64
- func MulDivRoundUpU64(a, b, c uint64) (uint64, error)
- func MulDivU64(a, b, c uint64) (uint64, error)
- func MulU64Big(a, b uint64) *big.Int
- func NotionalValueU64(price, quantity, precision uint64) (uint64, error)
- func SafeAddU64(a, b uint64) (uint64, error)
- func SafeDivU64(a, b uint64) (uint64, error)
- func SafeMulU64(a, b uint64) (uint64, error)
- func SafeSubU64(a, b uint64) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOverflow indicates an arithmetic overflow. ErrOverflow = errors.New("arithmetic overflow") // ErrDivisionByZero indicates division by zero. ErrDivisionByZero = errors.New("division by zero") )
Functions ¶
func BigMulDiv ¶
BigMulDiv computes (a * b) / c using big.Int arithmetic. All inputs and output are *big.Int. Returns nil if c is zero.
func BigMulDivRoundUp ¶
BigMulDivRoundUp computes ceil((a * b) / c) using big.Int arithmetic.
func CheckAddOverflowU64 ¶
CheckAddOverflowU64 returns true if a + b would overflow uint64.
func CheckMulOverflowU64 ¶
CheckMulOverflowU64 returns true if a * b would overflow uint64.
func MulDivRoundUpU64 ¶
MulDivRoundUpU64 computes ceil((a * b) / c) using big.Int. Returns an error if c is zero or if the result overflows uint64.
func MulDivU64 ¶
MulDivU64 computes (a * b) / c using big.Int to avoid intermediate overflow. Returns an error if c is zero or if the result overflows uint64.
func MulU64Big ¶
MulU64Big multiplies two uint64 values using big.Int to avoid overflow. Returns the result as a big.Int.
func NotionalValueU64 ¶
NotionalValueU64 calculates price * quantity / precision safely. This is a common operation in orderbooks.
func SafeAddU64 ¶
SafeAddU64 adds two uint64 values and returns an error on overflow.
func SafeDivU64 ¶
SafeDivU64 divides two uint64 values and returns an error on division by zero.
func SafeMulU64 ¶
SafeMulU64 multiplies two uint64 values and returns an error on overflow.
func SafeSubU64 ¶
SafeSubU64 subtracts two uint64 values and returns an error on underflow.
Types ¶
This section is empty.