Documentation ¶
Index ¶
- 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) 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) 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) 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) 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) 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) 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) 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 ¶
This section is empty.
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 (*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) 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) ExtendSign ¶ added in v1.0.0
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) 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) 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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
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.
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 ¶
Sub sets z to the difference x-y and returns true if the operation underflowed
func (*Int) SubUint64 ¶ added in v1.0.0
SubUint64 set z to the difference x - y, where y is a uint64, and returns z
func (*Int) Uint64 ¶
func (z *Int) WriteToArr32(dest [32]bytes){ for i := 0; i < 32; i++ { dest[31-i] = byte(z[i/8] >> uint64(8*(i%8))) } }
Uint64 returns the lower 64-bits of z
func (*Int) Uint64WithOverflow ¶
Uint64 returns the lower 64-bits of z and bool whether overflow occurred
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