{"modulePath":"github.com/Evolution404/simcore","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package math\n\nPackage math provides integer math utilities.\n\n## Constants\n\n```go\nconst (\n\tMaxInt8   = 1\u003c\u003c7 - 1\n\tMinInt8   = -1 \u003c\u003c 7\n\tMaxInt16  = 1\u003c\u003c15 - 1\n\tMinInt16  = -1 \u003c\u003c 15\n\tMaxInt32  = 1\u003c\u003c31 - 1\n\tMinInt32  = -1 \u003c\u003c 31\n\tMaxInt64  = 1\u003c\u003c63 - 1\n\tMinInt64  = -1 \u003c\u003c 63\n\tMaxUint8  = 1\u003c\u003c8 - 1\n\tMaxUint16 = 1\u003c\u003c16 - 1\n\tMaxUint32 = 1\u003c\u003c32 - 1\n\tMaxUint64 = 1\u003c\u003c64 - 1\n)\n```\nInteger limit values.\n\n## Variables\n\n```go\nvar (\n\tMaxBig256 = new(big.Int).Set(tt256m1)\n\tMaxBig63  = new(big.Int).Sub(tt63, big.NewInt(1))\n)\n```\nVarious big integer limit values.\n\n## Functions\n\n```go\nfunc BigMax(x, y *big.Int) *big.Int\n```\nBigMax returns the larger of x or y.\n\n```go\nfunc BigMin(x, y *big.Int) *big.Int\n```\nBigMin returns the smaller of x or y.\n\n```go\nfunc BigPow(a, b int64) *big.Int\n```\nBigPow returns a \\*\\* b as a big integer.\n\n```go\nfunc Byte(bigint *big.Int, padlength, n int) byte\n```\nByte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 =\u003e 5\n\n```go\nfunc Exp(base, exponent *big.Int) *big.Int\n```\nExp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.\n\nCourtesy @karalabe and @chfast\n\n```go\nfunc FirstBitSet(v *big.Int) int\n```\nFirstBitSet returns the index of the first 1 bit in v, counting from LSB.\n\n```go\nfunc MustParseBig256(s string) *big.Int\n```\nMustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.\n\n```go\nfunc MustParseUint64(s string) uint64\n```\nMustParseUint64 parses s as an integer and panics if the string is invalid.\n\n```go\nfunc PaddedBigBytes(bigint *big.Int, n int) []byte\n```\nPaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.\n\n```go\nfunc ParseBig256(s string) (*big.Int, bool)\n```\nParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.\n\n```go\nfunc ParseUint64(s string) (uint64, bool)\n```\nParseUint64 parses s as an integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.\n\n```go\nfunc ReadBits(bigint *big.Int, buf []byte)\n```\nReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.\n\n```go\nfunc S256(x *big.Int) *big.Int\n```\nS256 interprets x as a two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.\n\n\tS256(0)        = 0\n\tS256(1)        = 1\n\tS256(2**255)   = -2**255\n\tS256(2**256-1) = -1\n\n```go\nfunc SafeAdd(x, y uint64) (uint64, bool)\n```\nSafeAdd returns x+y and checks for overflow.\n\n```go\nfunc SafeMul(x, y uint64) (uint64, bool)\n```\nSafeMul returns x\\*y and checks for overflow.\n\n```go\nfunc SafeSub(x, y uint64) (uint64, bool)\n```\nSafeSub returns x-y and checks for overflow.\n\n```go\nfunc U256(x *big.Int) *big.Int\n```\nU256 encodes as a 256 bit two's complement number. This operation is destructive.\n\n```go\nfunc U256Bytes(n *big.Int) []byte\n```\nU256Bytes converts a big Int into a 256bit EVM number. This operation is destructive.\n\n## Types\n\n```go\ntype Decimal256 big.Int\n```\nDecimal256 unmarshals big.Int as a decimal string. When unmarshalling, it however accepts either \"0x\"-prefixed (hex encoded) or non-prefixed (decimal)\n\n```go\nfunc NewDecimal256(x int64) *Decimal256\n```\nNewHexOrDecimal256 creates a new Decimal256\n\n```go\nfunc (i *Decimal256) MarshalText() ([]byte, error)\n```\nMarshalText implements encoding.TextMarshaler.\n\n```go\nfunc (i *Decimal256) String() string\n```\nString implements Stringer.\n\n```go\nfunc (i *Decimal256) UnmarshalText(input []byte) error\n```\nUnmarshalText implements encoding.TextUnmarshaler.\n\n```go\ntype HexOrDecimal256 big.Int\n```\nHexOrDecimal256 marshals big.Int as hex or decimal.\n\n```go\nfunc NewHexOrDecimal256(x int64) *HexOrDecimal256\n```\nNewHexOrDecimal256 creates a new HexOrDecimal256\n\n```go\nfunc (i *HexOrDecimal256) MarshalText() ([]byte, error)\n```\nMarshalText implements encoding.TextMarshaler.\n\n```go\nfunc (i *HexOrDecimal256) UnmarshalText(input []byte) error\n```\nUnmarshalText implements encoding.TextUnmarshaler.\n\n```go\ntype HexOrDecimal64 uint64\n```\nHexOrDecimal64 marshals uint64 as hex or decimal.\n\n```go\nfunc (i HexOrDecimal64) MarshalText() ([]byte, error)\n```\nMarshalText implements encoding.TextMarshaler.\n\n```go\nfunc (i *HexOrDecimal64) UnmarshalText(input []byte) error\n```\nUnmarshalText implements encoding.TextUnmarshaler.\n\n","path":"github.com/Evolution404/simcore/common/math","name":"math","synopsis":"Package math provides integer math utilities.","isRedistributable":true}
