PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

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/uint256/v1

Package
Open in gnoweb ↗

Overview

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

Files (10)

  • README.mdmarkdown
  • gnomod.tomltoml
  • arithmetic.gnogno
  • bitwise.gnogno
  • cmp.gnogno
  • conversion.gnogno
  • doc.gnogno
  • fullmath.gnogno
  • mod.gnogno
  • uint256.gnogno
  • README.mdPreviewRaw
    # uint256
    
    256-bit unsigned integer arithmetic for GnoSwap.
    
    ## Overview
    
    Fixed-size 256-bit unsigned integer library optimized for AMM calculations with
    precise `MulDiv` operations. The unsuffixed `Add`, `Sub`, and `Mul` methods
    return the low 256 bits; the corresponding `AddOverflow`, `SubOverflow`, and
    `MulOverflow` variants also report an overflow/underflow flag.
    
    ## Features
    
    - Fixed 256-bit size (4 uint64 values)
    - Explicit overflow detection via `*Overflow` variants
    - Optimized `MulDiv` for precise calculations
    - Decimal string conversion
    - Range: 0 to 2^256-1
    
    ## Usage
    
    ```go
    package main
    
    import u256 "gno.land/p/gnoswap/uint256/v1"
    
    func main() {
        a := u256.NewUint(1000)
        b := u256.MustFromDecimal("1000000000000000000")
        result, overflow := new(u256.Uint).AddOverflow(a, b)
        if overflow {
            panic("unsigned addition overflow")
        }
        println(result.ToString()) // 1000000000000001000
    
        // MulDiv calculates floor(a*b/c). The denominator must be non-zero,
        // and the quotient must fit in 256 bits; otherwise it panics.
        c := u256.NewUint(3)
        println(u256.MulDiv(a, b, c).ToString()) // 333333333333333333333
    }
    ```
    
    ## Credits
    
    Ported from [holiman/uint256](https://github.com/holiman/uint256)

    Functions

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

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