PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/gnoswap/gnsmath/v1

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v1
Namespace
gnoswap / gnsmath
Files
11 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/gnoswap/gnsmath/v1
gno
0.9

Files (11)

  • README.mdmarkdown
  • gnomod.tomltoml
  • bit_math.gnogno
  • consts.gnogno
  • doc.gnogno
  • errors.gnogno
  • liquidity_math.gnogno
  • safe_math.gnogno
  • sqrt_price_math.gnogno
  • swap_math.gnogno
  • tick_math.gnogno
  • bit_math.gnogno
    1package gnsmath23import (4	"math/bits"56	u256 "gno.land/p/gnoswap/uint256/v1"7)89// BitMathMostSignificantBit returns the 0-based position of the most significant bit in x.10// This function is essential for AMM calculations involving price ranges and tick boundaries.11//12// Parameters:13//   - x: the non-zero value for which to compute the most significant set bit14//15// Returns:16//   - bitIndex: the zero-based position of the most significant set bit (0-255)17//18// Panics if x is zero.19func BitMathMostSignificantBit(x *u256.Uint) uint8 {20	if x.IsZero() {21		panic(errMSBZeroInput)22	}2324	return uint8(x.BitLen() - 1)25}2627// BitMathLeastSignificantBit returns the 0-based position of the least significant bit in x.28// This function is used in AMM calculations for efficient bit manipulation and range queries.29//30// Parameters:31//   - x: the non-zero value for which to compute the least significant set bit32//33// Returns:34//   - bitIndex: the zero-based position of the least significant set bit (0-255)35//36// Panics if x is zero.37func BitMathLeastSignificantBit(x *u256.Uint) uint8 {38	if x.IsZero() {39		panic(errLSBZeroInput)40	}4142	if x[0] != 0 {43		return uint8(bits.TrailingZeros64(x[0]))44	}45	if x[1] != 0 {46		return uint8(64 + bits.TrailingZeros64(x[1]))47	}48	if x[2] != 0 {49		return uint8(128 + bits.TrailingZeros64(x[2]))50	}51	return uint8(192 + bits.TrailingZeros64(x[3]))52}53

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.