math

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[V constraints.Signed](val V) V

Abs returns the absolute value of a given number.

func BigFloatToBigInt

func BigFloatToBigInt(f *big.Float, decimals uint64) *big.Int

BigFloatToBigInt converts a big.Float to a big.Int.

func CalculateMedian

func CalculateMedian(values []*big.Float) *big.Float

CalculateMedian calculates the median from a list of big.Float. Returns an average if the number of values is even.

func Float64StringToBigFloat

func Float64StringToBigFloat(s string) (*big.Float, error)

Float64StringToBigFloat converts a float64 string to a big.Float.

func Float64StringToBigInt

func Float64StringToBigInt(s string, decimals uint64) (*big.Int, error)

Float64StringToBigInt converts a float64 string to a big.Int.

func Float64ToBigInt

func Float64ToBigInt(val float64, decimals uint64) *big.Int

Float64ToBigInt converts a float64 to a big.Int.

func GetScalingFactor

func GetScalingFactor(
	first, second int64,
) *big.Float

GetScalingFactor returns the scaling factor for the price based on the difference between the token decimals in the erc20 token contracts or similar.

func Max

func Max[V int | int64 | uint64 | int32 | uint32](vals ...V) V

Max returns the maximum of two values.

func Min

func Min[V int | int64 | uint64 | int32 | uint32](vals ...V) V

Min returns the minimum of two values.

func ScaleBigFloat

func ScaleBigFloat(f *big.Float, decimals uint64) *big.Float

ScaleBigFloat scales a big.Float by the given decimals.

func SortBigFloats

func SortBigFloats(values []*big.Float)

SortBigFloats is a stable slices sort for an array of big.Floats.

func VerifyPrice

func VerifyPrice(
	t *testing.T,
	expected,
	actual *big.Int,
	acceptableDelta float64,
)

VerifyPrice verifies that the expected price matches the actual price within an acceptable delta.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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