Documentation ¶
Index ¶
- Variables
- func Reciprocal(m *Int) (mu [5]uint64)
- 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) (*Int, bool)
- func (z *Int) AddUint64(x *Int, y uint64) *Int
- 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) CmpBig(x *big.Int) (r int)
- func (z *Int) CmpUint64(x uint64) int
- func (z *Int) Dec() string
- func (z *Int) Div(x, y *Int) *Int
- func (z *Int) DivMod(x, y, m *Int) (*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) Float64() float64
- 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) HashTreeRoot() ([32]byte, error)
- func (z *Int) Hex() string
- func (z *Int) IsUint64() bool
- func (z *Int) IsZero() bool
- func (z *Int) Log10() uint
- 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) MarshalJSON() ([]byte, error)
- func (z *Int) MarshalSSZ() ([]byte, error)
- func (z *Int) MarshalSSZTo(dst []byte) ([]byte, error)
- 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) MulDivOverflow(x, y, d *Int) (*Int, bool)
- func (z *Int) MulMod(x, y, m *Int) *Int
- func (z *Int) MulModWithReciprocal(x, y, m *Int, mu *[5]uint64) *Int
- func (z *Int) MulOverflow(x, y *Int) (*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) PrettyDec(separator byte) string
- 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 (dst *Int) Scan(src interface{}) error
- 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) SetFromDecimal(s string) (err error)
- func (z *Int) SetFromHex(hex string) error
- 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 (*Int) SizeSSZ() int
- func (z *Int) Slt(x *Int) bool
- func (z *Int) Sqrt(x *Int) *Int
- func (z *Int) String() string
- func (z *Int) Sub(x, y *Int) *Int
- func (z *Int) SubOverflow(x, y *Int) (*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) UnmarshalSSZ(buf []byte) error
- func (z *Int) UnmarshalText(input []byte) error
- func (src *Int) Value() (driver.Value, 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") ErrBadBufferLength = errors.New("bad ssz buffer length") ErrBadEncodedLength = errors.New("bad ssz encoded length") )
Functions ¶
func Reciprocal ¶
Reciprocal computes a 320-bit value representing 1/m
Notes: - specialized for m[3] != 0, hence limited to 2^192 <= m < 2^256 - returns zero if m[3] == 0 - starts with a 32-bit division, refines with newton-raphson iterations
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. OBS: If b is `nil`, this method returns `nil, false`
func FromDecimal ¶
FromDecimal is a convenience-constructor to create an Int from a decimal (base 10) string. Numbers larger than 256 bits are not accepted.
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 MustFromBig ¶
MustFromBig is a convenience-constructor from big.Int. Returns a new Int and panics if overflow occurred. OBS: If b is `nil`, this method does _not_ panic, but instead returns `nil`
func MustFromDecimal ¶
MustFromDecimal is a convenience-constructor to create an Int from a decimal (base 10) string. Returns a new Int and panics if any error occurred.
func MustFromHex ¶
MustFromHex is a convenience-constructor to create an Int from a hexadecimal string. Returns a new Int and panics if any error 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) 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 z and 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) DivMod ¶
DivMod sets z to the quotient x div y and m to the modulus x mod y and returns the pair (z, m) for y != 0. If y == 0, both z and m are set to 0 (OBS: differs from the big.Int)
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) Float64 ¶
Float64 returns the float64 value nearest to x.
Note: The `big.Float` version of `Float64` also returns an 'Accuracy', indicating whether the value was too small or too large to be represented by a `float64`. However, the `uint256` type is unable to represent values out of scope (|x| < math.SmallestNonzeroFloat64 or |x| > math.MaxFloat64), therefore this method does not return any accuracy.
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) HashTreeRoot ¶
HashTreeRoot implements the fastssz.HashRoot interface's non-dependent part.
func (*Int) Log10 ¶
Log10 returns the log in base 10, floored to nearest integer. **OBS** This method returns '0' for '0', not `-Inf`.
func (*Int) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Int) MarshalSSZ ¶
MarshalSSZ implements the fastssz.Marshaler interface and returns the integer marshalled into a newly allocated byte slice.
func (*Int) MarshalSSZTo ¶
MarshalSSZTo implements the fastssz.Marshaler interface and serializes the integer into an already pre-allocated buffer.
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) MulDivOverflow ¶
MulDivOverflow calculates (x*y)/d with full precision, returns z and whether overflow occurred in multiply process (result does not fit to 256-bit). computes 512-bit multiplication and 512 by 256 division.
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) MulModWithReciprocal ¶
MulModWithReciprocal calculates the modulo-m multiplication of x and y and returns z, using the reciprocal of m provided as the mu parameter. Use uint256.Reciprocal to calculate mu from m. 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 z and 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) PrettyDec ¶
PrettyDec returns the decimal representation of z, with thousands-separators.
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) Scan ¶
Scan implements the database/sql Scanner interface. It decodes a string, because that is what postgres uses for its numeric type
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) SetFromDecimal ¶
SetFromDecimal sets z from the given string, interpreted as a decimal number. OBS! This method is _not_ strictly identical to the (*big.Int).SetString(..., 10) method. Notable differences: - This method does not accept underscore input, e.g. "100_000", - This method does not accept negative zero as valid, e.g "-0",
- (this method does not accept any negative input as valid))
func (*Int) SetFromHex ¶
SetFromHex sets z from the given string, interpreted as a hexadecimal number. OBS! This method is _not_ strictly identical to the (*big.Int).SetString(..., 16) method. Notable differences: - This method _require_ "0x" or "0X" prefix. - This method does not accept zero-prefixed hex, e.g. "0x0001" - This method does not accept underscore input, e.g. "100_000", - This method does not accept negative zero as valid, e.g "-0x0",
- (this method does not accept any negative input as valid)
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) SizeSSZ ¶
SizeSSZ implements the fastssz.Marshaler interface and returns the byte size of the 256 bit int.
func (*Int) SubOverflow ¶
SubOverflow sets z to the difference x-y and returns z and 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. Improvement: Unmarshal for int field, string of decimal.
func (*Int) UnmarshalSSZ ¶
UnmarshalSSZ implements the fastssz.Unmarshaler interface and parses an encoded integer into the local struct.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
func (*Int) Value ¶
Value implements the database/sql/driver Valuer interface. It encodes a base 10 string. In Postgres, this will work with both integer and the Numeric/Decimal types In MariaDB/MySQL, this will work with the Numeric/Decimal types up to 65 digits, however any more and you should use either VarChar or Char(79) In SqLite, use TEXT
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