Class UInt192


  • final class UInt192
    extends java.lang.Object
    A mutable 192-bit unsigned integer.

    This is a specialised class to implement an accumulator of squared long values.

    Since:
    1.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long ab
      bits 192-129 (high 64-bits).
      private int c
      bits 128-97.
      private int d
      bits 96-65.
      private int e
      bits 64-33.
      private int f
      bits 32-1 (low 32-bits).
      private static long MASK32
      Mask for the lower 32-bits of a long.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private UInt192()
      Create an instance.
      private UInt192​(long ab, int c, int d, int e, int f)
      Create an instance using a direct binary representation.
      (package private) UInt192​(long hi, long mid, long lo)
      Create an instance using a direct binary representation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void add​(UInt192 x)
      Adds the value.
      (package private) void addSquare​(long x)
      Adds the squared value x * x.
      (package private) static UInt192 create()
      Create an instance.
      (package private) long hi64()
      Return the higher 64-bits as a long value.
      (package private) long lo64()
      Return the lower 64-bits as a long value.
      (package private) long mid64()
      Return the middle 64-bits as a long value.
      (package private) UInt192 subtract​(UInt128 x)
      Subtracts the value.
      (package private) java.math.BigInteger toBigInteger()
      Convert to a BigInteger.
      (package private) double toDouble()
      Convert to a double.
      (package private) int toIntExact()
      Convert to an int; throwing an exception if the value overflows an int.
      (package private) long toLongExact()
      Convert to a long; throwing an exception if the value overflows a long.
      (package private) UInt192 unsignedMultiply​(int x)
      Multiply by the unsigned value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MASK32

        private static final long MASK32
        Mask for the lower 32-bits of a long.
        See Also:
        Constant Field Values
      • f

        private int f
        bits 32-1 (low 32-bits).
      • e

        private int e
        bits 64-33.
      • d

        private int d
        bits 96-65.
      • c

        private int c
        bits 128-97.
      • ab

        private long ab
        bits 192-129 (high 64-bits).
    • Constructor Detail

      • UInt192

        private UInt192()
        Create an instance.
      • UInt192

        UInt192​(long hi,
                long mid,
                long lo)
        Create an instance using a direct binary representation. This is package-private for testing.
        Parameters:
        hi - High 64-bits.
        mid - Middle 64-bits.
        lo - Low 64-bits.
      • UInt192

        private UInt192​(long ab,
                        int c,
                        int d,
                        int e,
                        int f)
        Create an instance using a direct binary representation.
        Parameters:
        ab - bits 192-129 (high 64-bits).
        c - bits 128-97.
        d - bits 96-65.
        e - bits 64-33.
        f - bits 32-1.
    • Method Detail

      • create

        static UInt192 create()
        Create an instance. The initial value is zero.
        Returns:
        the instance
      • addSquare

        void addSquare​(long x)
        Adds the squared value x * x.
        Parameters:
        x - Value.
      • add

        void add​(UInt192 x)
        Adds the value.
        Parameters:
        x - Value.
      • unsignedMultiply

        UInt192 unsignedMultiply​(int x)
        Multiply by the unsigned value. Any overflow bits are lost.
        Parameters:
        x - Value.
        Returns:
        the product
      • subtract

        UInt192 subtract​(UInt128 x)
        Subtracts the value. Any overflow bits (negative result) are lost.
        Parameters:
        x - Value.
        Returns:
        the difference
      • toBigInteger

        java.math.BigInteger toBigInteger()
        Convert to a BigInteger.
        Returns:
        the value
      • toDouble

        double toDouble()
        Convert to a double.
        Returns:
        the value
      • toIntExact

        int toIntExact()
        Convert to an int; throwing an exception if the value overflows an int.
        Returns:
        the value
        Throws:
        java.lang.ArithmeticException - if the value overflows an int.
        See Also:
        Math.toIntExact(long)
      • toLongExact

        long toLongExact()
        Convert to a long; throwing an exception if the value overflows a long.
        Returns:
        the value
        Throws:
        java.lang.ArithmeticException - if the value overflows a long.
      • lo64

        long lo64()
        Return the lower 64-bits as a long value.
        Returns:
        the low 64-bits
      • mid64

        long mid64()
        Return the middle 64-bits as a long value.
        Returns:
        bits 128-65
      • hi64

        long hi64()
        Return the higher 64-bits as a long value.
        Returns:
        bits 192-129