Documentation ¶
Index ¶
- Variables
- type Int
- func (z *Int) Abs(x *Int) *Int
- func (z *Int) Add(x, y *Int) *Int
- func (z *Int) AddMod(x, y, m *Int) *Int
- func (z *Int) AddOverflow(x, y *Int) bool
- func (z *Int) And(x, y *Int) *Int
- func (z *Int) BitLen() int
- func (z *Int) Byte(n *Int) *Int
- func (z *Int) ByteLen() int
- func (z *Int) Bytes() []byte
- func (z *Int) Bytes20() [20]byte
- func (z *Int) Bytes32() [32]byte
- func (z *Int) Clear() *Int
- func (z *Int) Clone() *Int
- func (z *Int) Cmp(x *Int) (r int)
- func (z *Int) Div(x, y *Int) *Int
- func (z *Int) EncodeRLP(w io.Writer) error
- func (z *Int) Eq(x *Int) bool
- func (z *Int) Exp(base, exponent *Int) *Int
- func (z *Int) ExtendSign(x, byteNum *Int) *Int
- func (z *Int) Format(s fmt.State, ch rune)
- func (z *Int) Gt(x *Int) bool
- func (z *Int) GtUint64(n uint64) bool
- func (z *Int) Hex() string
- func (z *Int) IsUint64() bool
- func (z *Int) IsZero() bool
- func (z *Int) Lsh(x *Int, n uint) *Int
- func (z *Int) Lt(x *Int) bool
- func (z *Int) LtUint64(n uint64) bool
- func (z *Int) MarshalText() ([]byte, error)
- func (z *Int) Mod(x, y *Int) *Int
- func (z *Int) Mul(x, y *Int) *Int
- func (z *Int) MulMod(x, y, m *Int) *Int
- func (z *Int) MulOverflow(x, y *Int) bool
- func (z *Int) Neg(x *Int) *Int
- func (z *Int) Not(x *Int) *Int
- func (z *Int) Or(x, y *Int) *Int
- func (z *Int) PaddedBytes(n int) []byte
- func (z *Int) Rsh(x *Int, n uint) *Int
- func (z *Int) SDiv(n, d *Int) *Int
- func (z *Int) SMod(x, y *Int) *Int
- func (z *Int) SRsh(x *Int, n uint) *Int
- func (z *Int) Set(x *Int) *Int
- func (z *Int) SetAllOne() *Int
- func (z *Int) SetBytes(buf []byte) *Int
- func (z *Int) SetBytes1(in []byte) *Int
- func (z *Int) SetBytes10(in []byte) *Int
- func (z *Int) SetBytes11(in []byte) *Int
- func (z *Int) SetBytes12(in []byte) *Int
- func (z *Int) SetBytes13(in []byte) *Int
- func (z *Int) SetBytes14(in []byte) *Int
- func (z *Int) SetBytes15(in []byte) *Int
- func (z *Int) SetBytes16(in []byte) *Int
- func (z *Int) SetBytes17(in []byte) *Int
- func (z *Int) SetBytes18(in []byte) *Int
- func (z *Int) SetBytes19(in []byte) *Int
- func (z *Int) SetBytes2(in []byte) *Int
- func (z *Int) SetBytes20(in []byte) *Int
- func (z *Int) SetBytes21(in []byte) *Int
- func (z *Int) SetBytes22(in []byte) *Int
- func (z *Int) SetBytes23(in []byte) *Int
- func (z *Int) SetBytes24(in []byte) *Int
- func (z *Int) SetBytes25(in []byte) *Int
- func (z *Int) SetBytes26(in []byte) *Int
- func (z *Int) SetBytes27(in []byte) *Int
- func (z *Int) SetBytes28(in []byte) *Int
- func (z *Int) SetBytes29(in []byte) *Int
- func (z *Int) SetBytes3(in []byte) *Int
- func (z *Int) SetBytes30(in []byte) *Int
- func (z *Int) SetBytes31(in []byte) *Int
- func (z *Int) SetBytes32(in []byte) *Int
- func (z *Int) SetBytes4(in []byte) *Int
- func (z *Int) SetBytes5(in []byte) *Int
- func (z *Int) SetBytes6(in []byte) *Int
- func (z *Int) SetBytes7(in []byte) *Int
- func (z *Int) SetBytes8(in []byte) *Int
- func (z *Int) SetBytes9(in []byte) *Int
- func (z *Int) SetFromBig(b *big.Int) bool
- func (z *Int) SetOne() *Int
- func (z *Int) SetUint64(x uint64) *Int
- func (z *Int) Sgt(x *Int) bool
- func (z *Int) Sign() int
- func (z *Int) Slt(x *Int) bool
- func (z *Int) String() string
- func (z *Int) Sub(x, y *Int) *Int
- func (z *Int) SubOverflow(x, y *Int) bool
- func (z *Int) SubUint64(x *Int, y uint64) *Int
- func (z *Int) ToBig() *big.Int
- func (z *Int) Uint64() uint64
- func (z *Int) Uint64WithOverflow() (uint64, bool)
- func (z *Int) UnmarshalJSON(input []byte) error
- func (z *Int) UnmarshalText(input []byte) error
- func (z *Int) WriteToArray20(dest *[20]byte)
- func (z *Int) WriteToArray32(dest *[32]byte)
- func (z *Int) WriteToSlice(dest []byte)
- func (z *Int) Xor(x, y *Int) *Int
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyString = errors.New("empty hex string") ErrSyntax = errors.New("invalid hex string") ErrMissingPrefix = errors.New("hex string without 0x prefix") ErrEmptyNumber = errors.New("hex string \"0x\"") ErrLeadingZero = errors.New("hex number with leading zero digits") ErrBig256Range = errors.New("hex number > 256 bits") ErrNonString = errors.New("non-string") )
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int [4]uint64
Int is represented as an array of 4 uint64, in little-endian order, so that Int[3] is the most significant, and Int[0] is the least significant
func FromBig ¶
FromBig is a convenience-constructor from big.Int. Returns a new Int and whether overflow occurred.
func FromHex ¶
FromHex is a convenience-constructor to create an Int from a hexadecimal string. The string is required to be '0x'-prefixed Numbers larger than 256 bits are not accepted.
func (*Int) Abs ¶
Abs interprets x as a two's complement signed number, and sets z to the absolute value
Abs(0) = 0 Abs(1) = 1 Abs(2**255) = -2**255 Abs(2**256-1) = -1
func (*Int) AddMod ¶
AddMod sets z to the sum ( x+y ) mod m, and returns z. If m == 0, z is set to 0 (OBS: differs from the big.Int)
func (*Int) AddOverflow ¶
AddOverflow sets z to the sum x+y, and returns whether overflow occurred
func (*Int) Byte ¶
Byte sets z to the value of the byte at position n, with 'z' considered as a big-endian 32-byte integer if 'n' > 32, f is set to 0 Example: f = '5', n=31 => 5
func (*Int) EncodeRLP ¶
EncodeRLP implements the rlp.Encoder interface from go-ethereum and writes the RLP encoding of z to w.
func (*Int) ExtendSign ¶
ExtendSign extends length of two’s complement signed integer, sets z to
- x if byteNum > 31
- x interpreted as a signed number with sign-bit at (byteNum*8+7), extended to the full 256 bits
and returns z.
func (*Int) Format ¶
Format implements fmt.Formatter. It accepts the formats 'b' (binary), 'o' (octal with 0 prefix), 'O' (octal with 0o prefix), 'd' (decimal), 'x' (lowercase hexadecimal), and 'X' (uppercase hexadecimal). Also supported are the full suite of package fmt's format flags for integral types, including '+' and ' ' for sign control, '#' for leading zero in octal and for hexadecimal, a leading "0x" or "0X" for "%#x" and "%#X" respectively, specification of minimum digits precision, output field width, space or zero padding, and '-' for left or right justification.
func (*Int) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Int) Mod ¶
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) MulMod ¶
MulMod calculates the modulo-m multiplication of x and y and returns z. If m == 0, z is set to 0 (OBS: differs from the big.Int)
func (*Int) MulOverflow ¶
MulOverflow sets z to the product x*y, and returns whether overflow occurred
func (*Int) PaddedBytes ¶
PaddedBytes encodes a Int as a 0-padded byte slice. The length of the slice is at least n bytes. Example, z =1, n = 20 => [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
func (*Int) SDiv ¶
SDiv interprets n and d as two's complement signed integers, does a signed division on the two operands and sets z to the result. If d == 0, z is set to 0
func (*Int) SMod ¶
SMod interprets x and y as two's complement signed integers, sets z to (sign x) * { abs(x) modulus abs(y) } If y == 0, z is set to 0 (OBS: differs from the big.Int)
func (*Int) SRsh ¶
SRsh (Signed/Arithmetic right shift) considers z to be a signed integer, during right-shift and sets z = x >> n and returns z.
func (*Int) SetBytes ¶
SetBytes interprets buf as the bytes of a big-endian unsigned integer, sets z to that value, and returns z. If buf is larger than 32 bytes, the last 32 bytes is used. This operation is semantically equivalent to `FromBig(new(big.Int).SetBytes(buf))`
func (*Int) SetBytes10 ¶
func (*Int) SetBytes11 ¶
func (*Int) SetBytes12 ¶
func (*Int) SetBytes13 ¶
func (*Int) SetBytes14 ¶
func (*Int) SetBytes15 ¶
func (*Int) SetBytes16 ¶
SetBytes16 is identical to SetBytes(in[:16]), but panics is input is too short
func (*Int) SetBytes17 ¶
func (*Int) SetBytes18 ¶
func (*Int) SetBytes19 ¶
func (*Int) SetBytes20 ¶
func (*Int) SetBytes21 ¶
func (*Int) SetBytes22 ¶
func (*Int) SetBytes23 ¶
func (*Int) SetBytes24 ¶
SetBytes16 is identical to SetBytes(in[:24]), but panics is input is too short
func (*Int) SetBytes25 ¶
func (*Int) SetBytes26 ¶
func (*Int) SetBytes27 ¶
func (*Int) SetBytes28 ¶
func (*Int) SetBytes29 ¶
func (*Int) SetBytes30 ¶
func (*Int) SetBytes31 ¶
func (*Int) SetBytes32 ¶
func (*Int) SetBytes8 ¶
SetBytes8 is identical to SetBytes(in[:8]), but panics is input is too short
func (*Int) SetFromBig ¶
SetFromBig converts a big.Int to Int and sets the value to z. TODO: Ensure we have sufficient testing, esp for negative bigints.
func (*Int) Sign ¶
Sign returns:
-1 if z < 0 0 if z == 0 +1 if z > 0
Where z is interpreted as a two's complement signed number
func (*Int) SubOverflow ¶
SubOverflow sets z to the difference x-y and returns true if the operation underflowed
func (*Int) Uint64WithOverflow ¶
Uint64WithOverflow returns the lower 64-bits of z and bool whether overflow occurred
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
func (*Int) WriteToArray20 ¶
WriteToArray20 writes the last 20 bytes of z to the destination array, including zero-bytes
func (*Int) WriteToArray32 ¶
WriteToArray32 writes all 32 bytes of z to the destination array, including zero-bytes
func (*Int) WriteToSlice ¶
WriteToSlice writes the content of z into the given byteslice. If dest is larger than 32 bytes, z will fill the first parts, and leave the end untouched. OBS! If dest is smaller than 32 bytes, only the end parts of z will be used for filling the array, making it useful for filling an Address object