// Package uniswap provides mathematical functions for Uniswap V3 calculations. package uniswap import ( "math" "math/big" "sync" ) var ( // Global cached constants initialized once to avoid recomputing them q96 *big.Int q192 *big.Int lnBase float64 // ln(1.0001) invLnBase float64 // 1 / ln(1.0001) q96Float *big.Float q192Float *big.Float once sync.Once ) // InitConstants initializes all global cached constants func InitConstants() { once.Do(func() { q96 = new(big.Int).Exp(big.NewInt(2), big.NewInt(96), nil) q192 = new(big.Int).Exp(big.NewInt(2), big.NewInt(192), nil) lnBase = math.Log(1.0001) invLnBase = 1.0 / lnBase q96Float = new(big.Float).SetPrec(256).SetInt(q96) q192Float = new(big.Float).SetPrec(256).SetInt(q192) }) } // initConstants initializes all global cached constants (alias for internal use) func initConstants() { InitConstants() } // GetQ96 returns the cached value of 2^96 func GetQ96() *big.Int { initConstants() return q96 } // GetQ192 returns the cached value of 2^192 func GetQ192() *big.Int { initConstants() return q192 } // GetLnBase returns the cached value of ln(1.0001) func GetLnBase() float64 { initConstants() return lnBase } // GetInvLnBase returns the cached value of 1/ln(1.0001) func GetInvLnBase() float64 { initConstants() return invLnBase } // GetQ96Float returns the cached value of 2^96 as big.Float func GetQ96Float() *big.Float { initConstants() return q96Float } // GetQ192Float returns the cached value of 2^192 as big.Float func GetQ192Float() *big.Float { initConstants() return q192Float }