Search Apps Documentation Source Content File Folder Download Copy Actions Download

/p/gnoswap/int256

Directory ยท 6 Files
README.md Open

int256

256-bit signed integer arithmetic for GnoSwap.

Overview

Fixed-size 256-bit signed integer library optimized for AMM calculations with overflow detection.

Features

  • Fixed 256-bit size (predictable gas costs)
  • Two's complement representation
  • Overflow detection on all operations
  • AMM-optimized functions
  • Range: -(2^255) to 2^255-1

Usage

 1import i256 "gno.land/p/gnoswap/int256"
 2
 3// Create values
 4a := i256.NewInt(100)
 5b := i256.MustFromDecimal("-1000")
 6
 7// Arithmetic with overflow detection
 8result, overflow := new(i256.Int).AddOverflow(a, b)
 9if overflow {
10    // Handle overflow
11}

Implementation

Built on uint256 for underlying arithmetic.