Search Apps Documentation Source Content File Folder Download Copy Actions Download

/p/gnoswap/uint256

Directory ยท 11 Files
README.md Open

uint256

256-bit unsigned integer arithmetic for GnoSwap.

Overview

Fixed-size 256-bit unsigned integer library optimized for AMM calculations with overflow detection and precise MulDiv operations.

Features

  • Fixed 256-bit size (4 uint64 values)
  • Overflow detection on all operations
  • Optimized MulDiv for precise calculations
  • String conversion (decimal, hex, binary)
  • Range: 0 to 2^256-1

Usage

 1import u256 "gno.land/p/gnoswap/uint256"
 2
 3// Create values
 4a := u256.NewUint(1000)
 5b := u256.MustFromDecimal("1000000000000000000")
 6
 7// Arithmetic with overflow detection
 8result, overflow := new(u256.Uint).AddOverflow(a, b)
 9if overflow {
10    // Handle overflow
11}
12
13// Precise MulDiv (a * b / c)
14result := u256.MulDiv(a, b, c)

Credits

Ported from holiman/uint256