Package com.norswap.nanoeth.data
Class Natural
java.lang.Object
java.lang.Number
java.math.BigInteger
com.norswap.nanoeth.data.Natural
- All Implemented Interfaces:
RLPLayoutable
,Serializable
,Comparable<BigInteger>
public final class Natural extends BigInteger implements RLPLayoutable
Represents an arbitrary-length natural (positive) integer.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static Natural
ZERO
Zero, as a natural, to avoid holding duplicated copies.Fields inherited from class java.math.BigInteger
ONE, TEN, TWO
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Natural
add(long value)
Natural
divide(long value)
boolean
greater(long value)
boolean
greaterSame(long value)
boolean
lower(long value)
boolean
lowerSame(long value)
Natural
mod(long value)
Natural
multiply(long value)
static Natural
parse(RLP rlp)
Parses a natural from the given RLP data.Natural
pow(int value)
RLP
rlpLayout()
Natural are encoded in RLP using only as many bytes as necessary, with no leading 0.boolean
same(long value)
Natural
subtract(long value)
String
toHexString()
Methods inherited from class java.math.BigInteger
abs, add, and, andNot, bitCount, bitLength, byteValueExact, clearBit, compareTo, divide, divideAndRemainder, doubleValue, equals, flipBit, floatValue, gcd, getLowestSetBit, hashCode, intValue, intValueExact, isProbablePrime, longValue, longValueExact, max, min, mod, modInverse, modPow, multiply, negate, nextProbablePrime, not, or, probablePrime, remainder, setBit, shiftLeft, shiftRight, shortValueExact, signum, sqrt, sqrtAndRemainder, subtract, testBit, toByteArray, toString, toString, valueOf, xor
Methods inherited from class java.lang.Number
byteValue, shortValue
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.norswap.nanoeth.rlp.RLPLayoutable
rlpEncode, rlpHexString
-
Field Details
-
ZERO
Zero, as a natural, to avoid holding duplicated copies.
-
-
Constructor Details
-
Natural
public Natural(long nat) -
Natural
Creates a natural from a hex-string (e.g. "0x123"). -
Natural
-
Natural
public Natural(byte[] nat)Constructs a natural from a big-endian byte array, which will be interpreted as a positive integer (e.g.[0xFF]
is 255, not -1).
-
-
Method Details
-
parse
Parses a natural from the given RLP data.- Throws:
RLPParsingException
- See Also:
rlpLayout()
-
same
public boolean same(long value) -
greater
public boolean greater(long value) -
lower
public boolean lower(long value) -
greaterSame
public boolean greaterSame(long value) -
lowerSame
public boolean lowerSame(long value) -
add
-
subtract
-
multiply
-
divide
-
mod
-
pow
- Overrides:
pow
in classBigInteger
-
toHexString
-
rlpLayout
Natural are encoded in RLP using only as many bytes as necessary, with no leading 0.Zero itself is represented by an empty byte array.
- Specified by:
rlpLayout
in interfaceRLPLayoutable
-