math

package
v1.5.53 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: GPL-3.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAdditionOverflow = errors.New("addition overflow")

ErrAdditionOverflow is raised when there is an overflow because of the addition of two numbers

View Source
var ErrBigFloatAdd = errors.New("this big Float operation is not permitted while doing float.Add")

ErrBigFloatAdd is raised when add of floats produces a panic

View Source
var ErrBigFloatMul = errors.New("this big Float operation is not permitted while doing float.Mul")

ErrBigFloatMul is raised when mul of floats produces a panic

View Source
var ErrBigFloatQuo = errors.New("this big Float operation is not permitted while doing float.Quo")

ErrBigFloatQuo is raised when quo of floats produces a panic

View Source
var ErrBigFloatSqrt = errors.New("this big Float operation is not permitted while doing float.Sqrt")

ErrBigFloatSqrt is raised when sqrt of floats produces a panic

View Source
var ErrBigFloatSub = errors.New("this big Float operation is not permitted while doing float.Sub")

ErrBigFloatSub is raised when sub of floats produces a panic

View Source
var ErrMultiplicationOverflow = errors.New("multiplication overflow")

ErrMultiplicationOverflow is raised when there is an overflow because of the multiplication of two numbers

View Source
var ErrOutOfBounds = errors.New("out of bounds")

ErrOutOfBounds is raised when slice start or length exceeds bounds

View Source
var ErrSubtractionUnderflow = errors.New("subtraction underflow")

ErrSubtractionUnderflow is raised when there is an underflow because of the subtraction of two numbers

Functions

func AddBigFloat

func AddBigFloat(op1, op2 *big.Float) (result *big.Float, err error)

AddBigFloat addition implementation with error handling for big float

func AddInt32

func AddInt32(a, b int32) int32

AddInt32 performs addition on int32 and logs an error if the addition overflows

func AddInt32WithErr added in v1.5.6

func AddInt32WithErr(a, b int32) (int32, error)

AddInt32WithErr performs addition on int32 and returns an error if the addition overflows

func AddUint64

func AddUint64(a, b uint64) uint64

AddUint64 performs addition on uint64 and logs an error if the addition overflows

func AddUint64WithErr

func AddUint64WithErr(a, b uint64) (uint64, error)

AddUint64WithErr performs addition on uint64 and returns an error if the addition overflows

func CheckBoundsInt32 added in v1.5.52

func CheckBoundsInt32(start, length int32, maxLen int) error

CheckBoundsInt32 validates that start and length are non-negative and int64(start)+int64(length) <= int64(maxLen)

func MulBigFloat

func MulBigFloat(op1, op2 *big.Float) (result *big.Float, err error)

MulBigFloat multiplication implementation with error handling for big float

func MulInt32 added in v1.5.47

func MulInt32(a, b int32) int32

MulInt32 performs multiplication on int32 and logs an error if the multiplication overflows

func MulInt32WithErr added in v1.5.47

func MulInt32WithErr(a, b int32) (int32, error)

MulInt32WithErr performs multiplication on int32 and returns an error if the multiplication overflows

func MulUint64

func MulUint64(a, b uint64) uint64

MulUint64 performs multiplication on uint64 and logs an error if the multiplication overflows

func MulUint64WithErr

func MulUint64WithErr(a, b uint64) (uint64, error)

MulUint64WithErr performs multiplication on uint64 and returns an error if the multiplication overflows

func NewOverflowHandler added in v1.5.6

func NewOverflowHandler() *overflowHandler

NewOverflowHandler creates a new instance of type overflowHandler This struct is not concurrent safe and should be instantiated for each chain of operations required to be executed

func NewSeedRandReader

func NewSeedRandReader(seed []byte) *seedRandReader

NewSeedRandReader creates and returns a new SeedRandReader

func QuoBigFloat

func QuoBigFloat(op1, op2 *big.Float) (result *big.Float, err error)

QuoBigFloat quotient implementation with error handling for big float

func SqrtBigFloat

func SqrtBigFloat(op *big.Float) (result *big.Float, err error)

SqrtBigFloat sqrt implementation with error handling for big float

func SubBigFloat

func SubBigFloat(op1, op2 *big.Float) (result *big.Float, err error)

SubBigFloat subtraction implementation with error handling for big float

func SubInt

func SubInt(a, b int) int

SubInt performs subtraction on int and logs an error if the subtraction overflows

func SubInt32 added in v1.5.52

func SubInt32(a, b int32) int32

SubInt32 performs subtraction on int32 and logs an error if the subtraction underflows

func SubInt32WithErr added in v1.5.52

func SubInt32WithErr(a, b int32) (int32, error)

SubInt32WithErr performs subtraction on int32 and returns an error if the subtraction underflows or overflows

func SubUint64

func SubUint64(a, b uint64) uint64

SubUint64 performs subtraction on uint64, in case of underflow returns 0

func SubUint64WithErr added in v1.5.52

func SubUint64WithErr(a, b uint64) (uint64, error)

SubUint64WithErr performs subtraction on uint64 and returns an error if the subtraction underflows

func TwosComplementByteLength added in v1.5.52

func TwosComplementByteLength(bi *big.Int) int

TwosComplementByteLength returns the number of bytes that the two's complement representation of the given value occupies, i.e. len(twos.ToBytes(bi)), without allocating or building that representation.

The length is derived from the bit length alone:

  • zero is encoded on 0 bytes;
  • a positive value needs BitLen() bits plus one sign bit that must be 0, hence BitLen()/8 + 1 bytes;
  • a negative value -a is encoded as the bit-negation of a-1 plus a sign bit that must be 1, hence BitLen(a-1)/8 + 1 bytes. BitLen(a-1) equals BitLen(a), except when a is an exact power of two, when it is one less.

TODO: move to mx-components-big-int/twos-complement after the next VM release.

func UnsignedByteLength added in v1.5.52

func UnsignedByteLength(bi *big.Int) int

UnsignedByteLength returns the number of bytes that the absolute value of the given big int occupies, i.e. len(bi.Bytes()), without allocating those bytes.

Note that, just like big.Int.Bytes, this disregards the sign.

Types

type RandomnessGenerator

type RandomnessGenerator interface {
	Read(p []byte) (n int, err error)
	IsInterfaceNil() bool
}

RandomnessGenerator will provide the interface to the main functionalities of the VM where randomness is needed

Jump to

Keyboard shortcuts

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