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/onbloc/int256/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
onbloc / int256
Files
12 (gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/onbloc/int256/v0
gno
0.9

Files (12)

  • gnomod.tomltoml
  • arithmetic.gnogno
  • bitwise.gnogno
  • cmp.gnogno
  • conversion.gnogno
  • doc.gnogno
  • int256.gnogno
  • arithmetic_test.gnogno
  • bitwise_test.gnogno
  • cmp_test.gnogno
  • conversion_test.gnogno
  • int256_test.gnogno
  • conversion.gnogno
    1package int25623import (4	"math"56	"gno.land/p/onbloc/uint256/v0"7)89// SetInt64 sets the Int to the value of the provided int64.10//11// This method allows for easy conversion from standard Go integer types12// to Int, correctly handling both positive and negative values.13func (z *Int) SetInt64(v int64) *Int {14	if v >= 0 {15		z.value.SetUint64(uint64(v))16	} else {17		z.value.SetUint64(uint64(-v)).Neg(&z.value)18	}19	return z20}2122// SetUint64 sets the Int to the value of the provided uint64.23func (z *Int) SetUint64(v uint64) *Int {24	z.value.SetUint64(v)25	return z26}2728// Uint64 returns the lower 64-bits of z29func (z *Int) Uint64() uint64 {30	if z.Sign() < 0 {31		panic("cannot convert negative int256 to uint64")32	}33	if z.value.Gt(uint256.NewUint(0).SetUint64(math.MaxUint64)) {34		panic("overflow: int256 does not fit in uint64 type")35	}36	return z.value.Uint64()37}3839// Int64 returns the lower 64-bits of z40func (z *Int) Int64() int64 {41	if z.Sign() >= 0 {42		if z.value.BitLen() > 64 {43			panic("overflow: int256 does not fit in int64 type")44		}45		return int64(z.value.Uint64())46	}47	var temp uint256.Uint48	temp.Sub(uint256.NewUint(0), &z.value) // temp = -z.value49	if temp.BitLen() > 64 {50		panic("overflow: int256 does not fit in int64 type")51	}52	return -int64(temp.Uint64())53}5455// Neg sets z to -x and returns z.)56func (z *Int) Neg(x *Int) *Int {57	if x.IsZero() {58		z.value.Clear()59	} else {60		z.value.Neg(&x.value)61	}62	return z63}6465// Set sets z to x and returns z.66func (z *Int) Set(x *Int) *Int {67	z.value.Set(&x.value)68	return z69}7071// SetFromUint256 converts a uint256.Uint to Int and sets the value to z.72func (z *Int) SetUint256(x *uint256.Uint) *Int {73	z.value.Set(x)74	return z75}7677// ToString returns a string representation of z in base 10.78// The string is prefixed with a minus sign if z is negative.79func (z *Int) String() string {80	if z.value.IsZero() {81		return "0"82	}83	sign := z.Sign()84	var temp uint256.Uint85	if sign >= 0 {86		temp.Set(&z.value)87	} else {88		// temp = -z.value89		temp.Sub(uint256.NewUint(0), &z.value)90	}91	s := temp.Dec()92	if sign < 0 {93		return "-" + s94	}95	return s96}9798// NilToZero returns the Int if it's not nil, or a new zero-valued Int otherwise.99//100// This method is useful for safely handling potentially nil Int pointers,101// ensuring that operations always have a valid Int to work with.102func (z *Int) NilToZero() *Int {103	if z == nil {104		return Zero()105	}106	return z107}108

    Functions

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

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