int256

package module
v0.0.0-...-7a148ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 2 Imported by: 0

README

int256

wrap uint256 to allow perform with negative number

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDelta

func AddDelta(z, x *uint256.Int, y *Int)

Sets z to the sum x + y, where z and x are uint256s and y is an int256.

func AddDeltaOverflow

func AddDeltaOverflow(z, x *uint256.Int, y *Int) bool

Sets z to the sum x + y, where z and x are uint256s and y is an int256.

Types

type Int

type Int struct {
	// contains filtered or unexported fields
}

func FromBig

func FromBig(x *big.Int) (*Int, bool)

func FromUint256

func FromUint256(x *uint256.Int) *Int

FromUint256 is a convenience-constructor from uint256.Int. Returns a new Int and whether overflow occurred. OBS: If u is `nil`, this method returns `nil, false`

func MustFromBig

func MustFromBig(x *big.Int) *Int

func New

func New() *Int

func NewInt

func NewInt(x int64) *Int

NewInt allocates and returns a new Int set to x.

func (*Int) Abs

func (z *Int) Abs() *uint256.Int

Abs returns |z|

func (*Int) AbsGt

func (z *Int) AbsGt(x *uint256.Int) bool

AbsGt returns true if |z| > x, where x is a uint256

func (*Int) AbsLt

func (z *Int) AbsLt(x *uint256.Int) bool

AbsLt returns true if |z| < x, where x is a uint256

func (*Int) Add

func (z *Int) Add(x, y *Int) *Int

func (*Int) AddUint256

func (z *Int) AddUint256(x *Int, y *uint256.Int) *Int

AddUint256 set z to the sum x + y, where y is a uint256, and returns z

func (*Int) And

func (z *Int) And(x, y *Int) *Int

And sets z = x & y and returns z.

func (*Int) Clone

func (z *Int) Clone() *Int

Clone creates a new Int identical to z

func (*Int) Cmp

func (z *Int) Cmp(x *Int) (r int)

Cmp compares x and y and returns:

-1 if x <  y
 0 if x == y
+1 if x >  y

func (*Int) Div

func (z *Int) Div(x, y *Int) *Int

func (*Int) DivUint256

func (z *Int) DivUint256(x *Int, y *uint256.Int) *Int

DivUint256 sets z to the quotient x/y, where y is a uint256, and returns z If y == 0, z is set to 0

func (*Int) Eq

func (z *Int) Eq(x *Int) bool

Eq returns true if z == x

func (*Int) Exp

func (z *Int) Exp(x, y, m *Int) *Int

Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z. If m == nil or m == 0, z = x**y unless y <= 0 then z = 1. If m != 0, y < 0, and x and m are not relatively prime, z is unchanged and nil is returned.

Modular exponentiation of inputs of a particular size is not a cryptographically constant-time operation.

func (*Int) Gt

func (z *Int) Gt(x *Int) bool

Gt returns true if z > x

func (*Int) Int64

func (z *Int) Int64() int64

func (*Int) IsZero

func (z *Int) IsZero() bool

IsZero returns true if z == 0

func (*Int) Lsh

func (z *Int) Lsh(x *Int, n uint) *Int

Lsh sets z = x << n and returns z.

func (*Int) Lt

func (z *Int) Lt(x *Int) bool

Lt returns true if z < x

func (*Int) MarshalJSON

func (z *Int) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Int) Mod

func (z *Int) Mod(x, y *Int) *Int

Mod sets z to the modulus x%y for y != 0 and returns z. If y == 0, z is set to 0 (OBS: differs from the big.Int)

func (*Int) Mul

func (z *Int) Mul(x, y *Int) *Int

Mul sets z to the product x*y and returns z.

func (*Int) MulUint256

func (z *Int) MulUint256(x *Int, y *uint256.Int) *Int

MulUint256 sets z to the product x*y, where y is a uint256, and returns z

func (*Int) Neg

func (z *Int) Neg(x *Int) *Int

Neg sets z to -x and returns z.

func (*Int) Or

func (z *Int) Or(x, y *Int) *Int

Or sets z = x | y and returns z.

func (*Int) Quo

func (z *Int) Quo(x, y *Int) *Int

Quo sets z to the quotient x/y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Quo implements truncated division (like Go); see QuoRem for more details.

func (*Int) Rem

func (z *Int) Rem(x, y *Int) *Int

Rem sets z to the remainder x%y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Rem implements truncated modulus (like Go); see QuoRem for more details.

func (*Int) Rsh

func (z *Int) Rsh(x *Int, n uint) *Int

Rsh sets z = x >> n and returns z.

func (*Int) Set

func (z *Int) Set(x *Int) *Int

Set sets z to x and returns z.

func (*Int) SetInt64

func (z *Int) SetInt64(x int64) *Int

SetInt64 sets z to x and returns z.

func (*Int) SetString

func (z *Int) SetString(s string) (*Int, error)

SetUint64 sets z to x and returns z.

func (*Int) SetUint256

func (z *Int) SetUint256(x *uint256.Int) *Int

SetFromUint256 converts a uint256.Int to Int and sets the value to z.

func (*Int) SetUint64

func (z *Int) SetUint64(x uint64) *Int

SetUint64 sets z to x and returns z.

func (*Int) Sign

func (z *Int) Sign() int

Sign returns:

-1 if x <  0
 0 if x == 0
+1 if x >  0

func (*Int) Sqrt

func (z *Int) Sqrt(x *Int) *Int

Sqrt sets z to ⌊√x⌋, the largest integer such that z² ≤ x, and returns z. It panics if x is negative.

func (*Int) String

func (z *Int) String() string

func (*Int) Sub

func (z *Int) Sub(x, y *Int) *Int

Sub sets z to the difference x-y and returns z.

func (*Int) SubUint256

func (z *Int) SubUint256(x *Int, y *uint256.Int) *Int

SubUint256 set z to the difference x - y, where y is a uint256, and returns z

func (*Int) ToBig

func (z *Int) ToBig() *big.Int

func (*Int) Uint64

func (z *Int) Uint64() uint64

Uint64 returns the lower 64-bits of z

func (*Int) UnmarshalJSON

func (z *Int) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL