Documentation
¶
Overview ¶
Package mathx provides focused math and probability helpers.
New code should import this package instead of the legacy mathutils path:
import "github.com/InsideGallery/core/mathx"
Compatibility: github.com/InsideGallery/core/mathutils remains available for existing consumers. Keep new math helpers in mathx so applications can migrate away from the legacy aggregate path without changing behavior.
Index ¶
- Constants
- func ApproximatelyEqual(a, b float64) bool
- func BigIntToHighAndLow(value *big.Int) (uint64, uint64)
- func CantorPair(k1, k2 uint64) uint64
- func CantorUnpair(pair uint64) (uint64, uint64)
- func Clamp(value, lowerLimit, upperLimit float64) float64
- func HighAndLowToBigInt(high, low uint64) *big.Int
- func IntStringToBigInt(str string) *big.Int
- func RandomDigitString(length int) string
- func Round(value, precision float64) float64
- func RoundWithPrecision(value, precision float64) float64
- func WeightIndex(probabilities map[interface{}]uint64) interface{}
Constants ¶
const DefaultPrecision = mathutils.DefaultPrecision
DefaultPrecision is the fallback precision used by RoundWithPrecision.
Variables ¶
This section is empty.
Functions ¶
func ApproximatelyEqual ¶
ApproximatelyEqual reports whether two floats are nearly equal.
func BigIntToHighAndLow ¶
BigIntToHighAndLow splits a big integer into high and low uint64 halves.
func CantorPair ¶
CantorPair pairs two uint64 values with the Cantor pairing function.
func CantorUnpair ¶
CantorUnpair splits a Cantor-paired uint64 into two values.
func HighAndLowToBigInt ¶
HighAndLowToBigInt joins high and low uint64 halves into a big integer.
func IntStringToBigInt ¶
IntStringToBigInt parses a base-10 integer string.
func RandomDigitString ¶
RandomDigitString returns a random byte string with the requested length.
func RoundWithPrecision ¶
RoundWithPrecision rounds a float using the requested precision.
func WeightIndex ¶
func WeightIndex(probabilities map[interface{}]uint64) interface{}
WeightIndex returns a weighted random key from the probability map.
Types ¶
This section is empty.