Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4830125

RFE: adding partial support for unsigned primitive integers and huge (128 bits)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs
    • x86
    • windows_2000



      Name: rmT116609 Date: 03/10/2003


      DESCRIPTION OF THE REQUEST :
      Java primitive number are byte (8 bits signed), short (16 bits signed), int (32 bits signed) and long (64 bits signed). In some case we have to use unsigned number to make some computation and it will be good to support this case. Some says we have to add ubyte, ushort, uint and ulong : I think this is the maximum case. But for the moment may be it will be judicious to add support of unsigned as a part of primitive wraping (i.e. in objects Byte, Short, Integer, Long).
      It may be the time for java to add capability to optimal arithmetic with 128 bits integers because 64 bits will make 128 bits operation as fast as actual 64 bits. we propose the keyword 'huge' and also the class Huge. Moreover algorithm like digest (SHA, MD5) and cryptography need to make operation on block of 128 bits size !

      It is clear that operation like "+", "-" and equality ("==" or "!=") give the same result if we suppose primitive signed or unsigned. But for "*", "/" and comparing ("<", ">", "<=", ">=") the result are false.
      The problem is somethat difficult for "*" and "/".

      Let us only propose a partial solution for comparing

      So we can add

      -- for class Byte
      public (native) static int compareUnsigned(byte byteAsUnsigned1, byte byteAsUnsigned2)
      public int compareToUnsigned(Byte anotherByteAsUnsigned)

      -- for class Short
      public (native) static int compareUnsigned(short shortAsUnsigned1, short shortAsUnsigned2)
      public int compareToUnsigned(Short anotherShortAsUnsigned)

      -- for class Integer
      public (native) static int compareUnsigned(int intAsUnsigned1, int intAsUnsigned2)
      public int compareToUnsigned(Integer anotherIntegerAsUnsigned)

      -- for class Long
      public (native) static int compareUnsigned(long longAsUnsigned1, long longAsUnsigned2)
      public int compareToUnsigned(Long anotherLongAsUnsigned)

      -- for class Huge
      public (native) static int compareUnsigned(huge hugeAsUnsigned1, huge hugeAsUnsigned2)
      public int compareToUnsigned(Huge anotherHugeAsUnsigned)

      -- for class Math

      public static byte minUnsigned(byte ua, byte ub)
      public static short minUnsigned(short ua, short ub)
      public static int minUnsigned(int ua, int ub)
      public static long minUnsigned(long ua, long ub)
      public static huge minUnsigned(huge ua, huge ub)

      public static byte maxUnsigned(byte ua, byte ub)
      public static short maxUnsigned(short ua, short ub)
      public static int maxUnsigned(int ua, int ub)
      public static long maxUnsigned(long ua, long ub)
      public static huge maxUnsigned(huge ua, huge ub)

      Except for "+", "-", "==", "!=", ">>>" and "<<", there is no specific support of unsigned primitive integers in java


      CUSTOMER SUBMITTED WORKAROUND :
      use short for unsigned byte
      use int for unsigned short
      use long for unsigned int
      use BigInteger for unsigned long
      use BigInteger for huge
      use BigInteger for unsigned huge
      (Review ID: 182199)
      ======================================================================

            darcy Joe Darcy
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: