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 Details

    • ZERO

      public static final Natural ZERO
      Zero, as a natural, to avoid holding duplicated copies.
  • Constructor Details

    • Natural

      public Natural​(long nat)
    • Natural

      public Natural​(String hexString)
      Creates a natural from a hex-string (e.g. "0x123").
    • Natural

      public Natural​(BigInteger nat)
    • 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

      public static Natural parse​(RLP rlp) throws RLPParsingException
      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

      public Natural add​(long value)
    • subtract

      public Natural subtract​(long value)
    • multiply

      public Natural multiply​(long value)
    • divide

      public Natural divide​(long value)
    • mod

      public Natural mod​(long value)
    • pow

      public Natural pow​(int value)
      Overrides:
      pow in class BigInteger
    • toHexString

      public String toHexString()
    • rlpLayout

      public RLP 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 interface RLPLayoutable