Class DecimalData


  • public final class DecimalData
    extends Object
    Routines to convert between decimal data types stored in byte arrays and Java binary types.

    All the converter routines require the precision of the decimal value to convert, which represents the number of decimal digits in the decimal value, not including the sign.

    Unicode Decimal values can be represented as either a char array or as a byte array where every Unicode character is represented by a pair of adjacent bytes.

    For embedded sign nibbles (4 bit integers representing values between 0x0 and 0xF inclusive) in External Decimal or Packed Decimal data, 0xB and 0xD represent a negative sign. All other sign nibble values represent a positive sign. For operations that produce an External Decimal or Packed Decimal result, the Data Access Accelerator library inserts the preferred positive sign code of 0xC if the result is positive, and a preferred negative sign code of 0xD if the result is negative. All values between 0x0 and 0xF inclusive are interpreted as valid sign codes.

    This library has full support for signed integers but only limited support for scale points (decimals). Scale points and other unrecognized characters found in input External, Unicode, or Packed Decimal byte arrays are not supported, and may cause IllegalArgumentExceptions or undefined results. BigDecimal inputs will have scale ignored (i.e. -1.23 will be interpreted as -123). When converting to BigDecimal (as output), a scale value may be explicitly specified as a separate parameter.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int EBCDIC_SIGN_EMBEDDED_LEADING
      External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the first byte.
      static int EBCDIC_SIGN_EMBEDDED_TRAILING
      External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the last byte.
      static int EBCDIC_SIGN_SEPARATE_LEADING
      External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes before the first byte of the number.
      static int EBCDIC_SIGN_SEPARATE_TRAILING
      External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes after the last byte of the number.
      static int UNICODE_SIGN_SEPARATE_LEADING
      Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the first character.
      static int UNICODE_SIGN_SEPARATE_TRAILING
      Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the last character.
      static int UNICODE_UNSIGNED
      Unicode Decimal data format where each digit is a Unicode character, there is no sign.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void convertBigDecimalToExternalDecimal​(BigDecimal bigDecimalValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a BigDecimal value to an External Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array.
      static void convertBigDecimalToPackedDecimal​(BigDecimal bigDecimalValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a BigDecimal into a Packed Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array.
      static void convertBigDecimalToUnicodeDecimal​(BigDecimal bigDecimalValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a BigDecimal value to a Unicode Decimal in a char array Overflow can happen if the BigDecimal does not fit into the result char array.
      static void convertBigIntegerToExternalDecimal​(BigInteger bigIntegerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a BigInteger value into an External Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array.
      static void convertBigIntegerToPackedDecimal​(BigInteger bigIntegerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a BigInteger value into a Packed Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array.
      static void convertBigIntegerToUnicodeDecimal​(BigInteger bigIntegerValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a BigInteger value to a Unicode Decimal in a char array Overflow can happen if the BigInteger does not fit into the char array.
      static BigDecimal convertExternalDecimalToBigDecimal​(byte[] externalDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)
      Converts an External Decimal in a byte array to a BigDecimal.
      static BigInteger convertExternalDecimalToBigInteger​(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Convert an External Decimal in a byte array to a BigInteger.
      static int convertExternalDecimalToInteger​(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts an External Decimal value in a byte array into a binary integer.
      static long convertExternalDecimalToLong​(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts an External Decimal value in a byte array into a long.
      static void convertExternalDecimalToPackedDecimal​(byte[] externalDecimal, int externalOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)
      Converts an External Decimal in a byte array to a Packed Decimal in another byte array.
      static void convertIntegerToExternalDecimal​(int integerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts an integer to an External Decimal in a byte array.
      static void convertIntegerToPackedDecimal​(int integerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a binary integer value into a signed Packed Decimal format.
      static void convertIntegerToUnicodeDecimal​(int integerValue, char[] unicodeDecimal, int offset, int precision, boolean checkoverflow, int unicodeType)
      Converts an integer to a Unicode Decimal in a char array Overflow can happen if the resulting External Decimal value does not fit into the char array, given the offset and precision.
      static void convertLongToExternalDecimal​(long longValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a long into an External Decimal in a byte array.
      static void convertLongToPackedDecimal​(long longValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a binary long value into signed Packed Decimal format.
      static void convertLongToUnicodeDecimal​(long longValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Converts a long to a Unicode Decimal in a char array Overflow can happen if the resulting Unicode Decimal value does not fit into the char array, given its precision and offset .
      static BigDecimal convertPackedDecimalToBigDecimal​(byte[] packedDecimal, int offset, int precision, int scale, boolean checkOverflow)
      Convert a Packed Decimal in a byte array to a BigDecimal.
      static BigInteger convertPackedDecimalToBigInteger​(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Convert a Packed Decimal in a byte array to a BigInteger.
      static void convertPackedDecimalToExternalDecimal​(byte[] packedDecimal, int packedOffset, byte[] externalDecimal, int externalOffset, int precision, int decimalType)
      Converts a Packed Decimal in a byte array into an External Decimal in another byte array.
      static int convertPackedDecimalToInteger​(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a Packed Decimal value in a byte array into a binary integer.
      static long convertPackedDecimalToLong​(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
      Converts a Packed Decimal value in a byte array into a binary long.
      static void convertPackedDecimalToUnicodeDecimal​(byte[] packedDecimal, int packedOffset, char[] unicodeDecimal, int unicodeOffset, int precision, int decimalType)
      Convert a Packed Decimal in a byte array to a Unicode Decimal in a char array.
      static BigDecimal convertUnicodeDecimalToBigDecimal​(char[] unicodeDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)
      Converts a Unicode Decimal in a char array to a BigDecimal.
      static BigInteger convertUnicodeDecimalToBigInteger​(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
      Convert a Unicode Decimal in a char array to a BigInteger.
      static int convertUnicodeDecimalToInteger​(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)
      Converts a Unicode Decimal value in a char array into a binary integer.
      static long convertUnicodeDecimalToLong​(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)
      Converts a Unicode Decimal value in a char array into a binary long.
      static void convertUnicodeDecimalToPackedDecimal​(char[] unicodeDecimal, int unicodeOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)
      Converts an Unicode Decimal in a char array to a Packed Decimal in a byte array.
    • Field Detail

      • EBCDIC_SIGN_EMBEDDED_TRAILING

        public static final int EBCDIC_SIGN_EMBEDDED_TRAILING
        External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the last byte.
        See Also:
        Constant Field Values
      • EBCDIC_SIGN_EMBEDDED_LEADING

        public static final int EBCDIC_SIGN_EMBEDDED_LEADING
        External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the first byte.
        See Also:
        Constant Field Values
      • EBCDIC_SIGN_SEPARATE_TRAILING

        public static final int EBCDIC_SIGN_SEPARATE_TRAILING
        External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes after the last byte of the number.
        See Also:
        Constant Field Values
      • EBCDIC_SIGN_SEPARATE_LEADING

        public static final int EBCDIC_SIGN_SEPARATE_LEADING
        External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes before the first byte of the number.
        See Also:
        Constant Field Values
      • UNICODE_UNSIGNED

        public static final int UNICODE_UNSIGNED
        Unicode Decimal data format where each digit is a Unicode character, there is no sign.
        See Also:
        Constant Field Values
      • UNICODE_SIGN_SEPARATE_LEADING

        public static final int UNICODE_SIGN_SEPARATE_LEADING
        Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the first character.
        See Also:
        Constant Field Values
      • UNICODE_SIGN_SEPARATE_TRAILING

        public static final int UNICODE_SIGN_SEPARATE_TRAILING
        Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the last character.
        See Also:
        Constant Field Values
    • Method Detail

      • convertIntegerToPackedDecimal

        public static void convertIntegerToPackedDecimal​(int integerValue,
                                                         byte[] packedDecimal,
                                                         int offset,
                                                         int precision,
                                                         boolean checkOverflow)
        Converts a binary integer value into a signed Packed Decimal format. The Packed Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting Packed Decimal does not fit into the result byte array, given the offset and precision. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        integerValue - the binary integer value to convert
        packedDecimal - byte array that will store the resulting Packed Decimal value
        offset - offset of the first byte of the Packed Decimal in packedDecimal
        precision - number of Packed Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal is null
        ArithmeticException - if the checkOverflow parameter is true and overflow occurs
      • convertIntegerToExternalDecimal

        public static void convertIntegerToExternalDecimal​(int integerValue,
                                                           byte[] externalDecimal,
                                                           int offset,
                                                           int precision,
                                                           boolean checkOverflow,
                                                           int decimalType)
        Converts an integer to an External Decimal in a byte array. The External Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting External Decimal value does not fit into the byte array, given the precision and offset. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        integerValue - the value to convert
        externalDecimal - the byte array which will hold the External Decimal on a successful return
        offset - the offset in the byte array at which the External Decimal should be located
        precision - the number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticExceptionwill be thrown if the designated array cannot hold the External Decimal.
        decimalType - constant value indicating the type of External Decimal
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if the checkOverflow parameter is true and overflow occurs
        IllegalArgumentException - if decimalType or precision is invalid
      • convertIntegerToUnicodeDecimal

        public static void convertIntegerToUnicodeDecimal​(int integerValue,
                                                          char[] unicodeDecimal,
                                                          int offset,
                                                          int precision,
                                                          boolean checkoverflow,
                                                          int unicodeType)
        Converts an integer to a Unicode Decimal in a char array Overflow can happen if the resulting External Decimal value does not fit into the char array, given the offset and precision. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        integerValue - the long value to convert
        unicodeDecimal - the char array which will hold the Unicode Decimal on a successful return
        offset - the offset in the char array where the Unicode Decimal would be located
        precision - the number of decimal digits. Maximum valid precision is 253
        checkoverflow - if true, when the designated an ArithmeticException
        unicodeType - constant value indicating the type of Unicode Decimal
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if the checkOverflow parameter is true and overflow occurs
        IllegalArgumentException - if the decimalType or precision is invalid
      • convertLongToPackedDecimal

        public static void convertLongToPackedDecimal​(long longValue,
                                                      byte[] packedDecimal,
                                                      int offset,
                                                      int precision,
                                                      boolean checkOverflow)
        Converts a binary long value into signed Packed Decimal format. The Packed Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting Packed Decimal does not fit into the result byte array, given the offset and precision . In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        longValue - the binary long value to convert
        packedDecimal - byte array that will store the resulting Packed Decimal value
        offset - offset of the first byte of the Packed Decimal in packedDecimal
        precision - number of Packed Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow), otherwise a truncated value is returned
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal is null
        ArithmeticException - the checkOverflow parameter is true and overflow occurs
      • convertLongToExternalDecimal

        public static void convertLongToExternalDecimal​(long longValue,
                                                        byte[] externalDecimal,
                                                        int offset,
                                                        int precision,
                                                        boolean checkOverflow,
                                                        int decimalType)
        Converts a long into an External Decimal in a byte array. The External Decimal will be padded with zeros on the left if necessary. Overflow can happen if the External Decimal value does not fit into the byte array, given its precision and offset. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        longValue - the value to convert
        externalDecimal - the byte array which will hold the External Decimal on a successful return
        offset - the offset into externalDecimal where External Decimal should be located
        precision - the number of decimal digits to convert. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException or IllegalArgumentException may be thrown
        decimalType - constant value indicating the type of External Decimal
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if the checkOverflow parameter is true and overflow occurs
        IllegalArgumentException - if the decimalType or precision is invalid
      • convertLongToUnicodeDecimal

        public static void convertLongToUnicodeDecimal​(long longValue,
                                                       char[] unicodeDecimal,
                                                       int offset,
                                                       int precision,
                                                       boolean checkOverflow,
                                                       int decimalType)
        Converts a long to a Unicode Decimal in a char array Overflow can happen if the resulting Unicode Decimal value does not fit into the char array, given its precision and offset . In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        longValue - the long value to convert
        unicodeDecimal - the char array which will hold the Unicode Decimal on a successful return
        offset - the offset in the char array where the Unicode Decimal would be located
        precision - the number of Unicode Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException or IllegalArgumentException may be thrown
        decimalType - constant value indicating the type of External Decimal
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if the checkOverflow parameter is true and overflow occurs
        IllegalArgumentException - if decimalType or precision is invalid
      • convertPackedDecimalToInteger

        public static int convertPackedDecimalToInteger​(byte[] packedDecimal,
                                                        int offset,
                                                        int precision,
                                                        boolean checkOverflow)
        Converts a Packed Decimal value in a byte array into a binary integer. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into a binary integer. When checkOverflow is true overflow results in an ArithmeticException, when false a truncated or invalid result is returned.
        Parameters:
        packedDecimal - byte array which contains the Packed Decimal value
        offset - offset of the first byte of the Packed Decimal in packedDecimal
        precision - number of Packed Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException may be thrown
        Returns:
        int the resulting binary integer value
        Throws:
        NullPointerException - if packedDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into an int (overflow)
      • convertPackedDecimalToLong

        public static long convertPackedDecimalToLong​(byte[] packedDecimal,
                                                      int offset,
                                                      int precision,
                                                      boolean checkOverflow)
        Converts a Packed Decimal value in a byte array into a binary long. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into a binary long. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        packedDecimal - byte array which contains the Packed Decimal value
        offset - offset of the first byte of the Packed Decimal in packedDecimal
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException may be thrown
        Returns:
        long the resulting binary long value
        Throws:
        NullPointerException - if packedDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into a long (overflow)
      • convertPackedDecimalToExternalDecimal

        public static void convertPackedDecimalToExternalDecimal​(byte[] packedDecimal,
                                                                 int packedOffset,
                                                                 byte[] externalDecimal,
                                                                 int externalOffset,
                                                                 int precision,
                                                                 int decimalType)
        Converts a Packed Decimal in a byte array into an External Decimal in another byte array. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative.
        Parameters:
        packedDecimal - byte array that holds the Packed Decimal to be converted
        packedOffset - offset in packedDecimal where the Packed Decimal is located
        externalDecimal - byte array that will hold the External Decimal on a successful return
        externalOffset - offset in externalOffset where the External Decimal is expected to be located
        precision - number of decimal digits
        decimalType - constant indicating the type of the decimal
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal or externalDecimal are null
        IllegalArgumentException - if precision or decimalType is invalid
      • convertPackedDecimalToUnicodeDecimal

        public static void convertPackedDecimalToUnicodeDecimal​(byte[] packedDecimal,
                                                                int packedOffset,
                                                                char[] unicodeDecimal,
                                                                int unicodeOffset,
                                                                int precision,
                                                                int decimalType)
        Convert a Packed Decimal in a byte array to a Unicode Decimal in a char array. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative.
        Parameters:
        packedDecimal - byte array that holds a Packed Decimal to be converted
        packedOffset - offset in packedDecimal where the Packed Decimal is located
        unicodeDecimal - char array that will hold the Unicode Decimal on a successful return
        unicodeOffset - offset in the byte array where the Unicode Decimal is expected to be located
        precision - number of decimal digits
        decimalType - constant value indicating the type of the External Decimal
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal or unicodeDecimal are null
        IllegalArgumentException - if precision or decimalType is invalid
      • convertPackedDecimalToBigInteger

        public static BigInteger convertPackedDecimalToBigInteger​(byte[] packedDecimal,
                                                                  int offset,
                                                                  int precision,
                                                                  boolean checkOverflow)
        Convert a Packed Decimal in a byte array to a BigInteger. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into the BigInteger. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        packedDecimal - byte array that holds the Packed Decimal to be converted
        offset - offset in packedDecimal where the Packed Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        Returns:
        BigInteger the resulting BigInteger
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal is null
      • convertPackedDecimalToBigDecimal

        public static BigDecimal convertPackedDecimalToBigDecimal​(byte[] packedDecimal,
                                                                  int offset,
                                                                  int precision,
                                                                  int scale,
                                                                  boolean checkOverflow)
        Convert a Packed Decimal in a byte array to a BigDecimal. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into the BigDecimal. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        packedDecimal - byte array that holds the Packed Decimal to be converted
        offset - offset in packedDecimal where the Packed Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        scale - scale of the BigDecimal to be returned
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        Returns:
        BigDecimal the resulting BigDecimal
        Throws:
        NullPointerException - if packedDecimal is null
        ArrayIndexOutOfBoundsException - /requires rounding if an invalid array access occurs
      • convertExternalDecimalToInteger

        public static int convertExternalDecimalToInteger​(byte[] externalDecimal,
                                                          int offset,
                                                          int precision,
                                                          boolean checkOverflow,
                                                          int decimalType)
        Converts an External Decimal value in a byte array into a binary integer. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending on decimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into a binary integer. In this case, when checkOverflow is true an ArithmeticException is thrown, when false the resulting number will be wrapped around starting at the minimum/maximum possible integer value.
        Parameters:
        externalDecimal - byte array which contains the External Decimal value
        offset - the offset where the External Decimal value is located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException or IllegalArgumentException may be thrown. If false and there is an overflow, the result is undefined.
        decimalType - constant value indicating the type of External Decimal
        Returns:
        int the resulting binary integer
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into a int (overflow)
        IllegalArgumentException - if precision or decimalType is invalid
      • convertExternalDecimalToLong

        public static long convertExternalDecimalToLong​(byte[] externalDecimal,
                                                        int offset,
                                                        int precision,
                                                        boolean checkOverflow,
                                                        int decimalType)
        Converts an External Decimal value in a byte array into a long. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending on decimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into a binary long. When checkOverflow is true overflow results in an ArithmeticException, when false the resulting number will be wrapped around starting at the minimum/maximum possible long value.
        Parameters:
        externalDecimal - byte array which contains the External Decimal value
        offset - offset of the first byte of the Packed Decimal in the externalDecimal
        precision - number of External Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown when the converted value cannot fit into designated External Decimal array. If false and there is an overflow, the result is undefined.
        decimalType - constant value indicating the type of External Decimal
        Returns:
        long the resulting binary long value
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into a long (overflow)
        IllegalArgumentException - if precision or decimalType is invalid
      • convertExternalDecimalToPackedDecimal

        public static void convertExternalDecimalToPackedDecimal​(byte[] externalDecimal,
                                                                 int externalOffset,
                                                                 byte[] packedDecimal,
                                                                 int packedOffset,
                                                                 int precision,
                                                                 int decimalType)
        Converts an External Decimal in a byte array to a Packed Decimal in another byte array. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending on decimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative.
        Parameters:
        externalDecimal - byte array holding the External Decimal to be converted
        externalOffset - offset in externalDecimal where the External Decimal is located
        packedDecimal - byte array which will hold the Packed Decimal on a successful return
        packedOffset - offset in packedDecimal where the Packed Decimal is expected to be located
        precision - the number of decimal digits
        decimalType - constant value indicating the type of External Decimal
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal or externalDecimal is null
        IllegalArgumentException - if precision or decimalType is invalid
      • convertExternalDecimalToBigInteger

        public static BigInteger convertExternalDecimalToBigInteger​(byte[] externalDecimal,
                                                                    int offset,
                                                                    int precision,
                                                                    boolean checkOverflow,
                                                                    int decimalType)
        Convert an External Decimal in a byte array to a BigInteger. The sign of the input External Decimal is assumed to to be positive unless the sign nibble or byte (depending on decimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into the BigInteger. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        externalDecimal - byte array that holds the Packed Decimal to be converted
        offset - offset in externalDecimal where the Packed Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value indicating the type of External Decimal
        Returns:
        BigInteger the resulting BigInteger
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if externalDecimal is null
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if decimalType or precision is invalid, or the digital part of the input is invalid.
      • convertExternalDecimalToBigDecimal

        public static BigDecimal convertExternalDecimalToBigDecimal​(byte[] externalDecimal,
                                                                    int offset,
                                                                    int precision,
                                                                    int scale,
                                                                    boolean checkOverflow,
                                                                    int decimalType)
        Converts an External Decimal in a byte array to a BigDecimal. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending on decimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into the BigDecimal. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        externalDecimal - byte array holding the External Decimal to be converted
        offset - offset in externalDecimal where the External Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        scale - scale of the BigDecimal
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value that indicates the type of External Decimal
        Returns:
        BigDecimal the resulting BigDecimal
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if checkOverflow is true and the Packed Decimal is in an invalid format, or the digital part of the input is invalid.
      • convertUnicodeDecimalToInteger

        public static int convertUnicodeDecimalToInteger​(char[] unicodeDecimal,
                                                         int offset,
                                                         int precision,
                                                         boolean checkOverflow,
                                                         int unicodeType)
        Converts a Unicode Decimal value in a char array into a binary integer. The sign of the input Unicode Decimal is assumed to be positive unless the sign char contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary int. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        unicodeDecimal - char array which contains the Unicode Decimal value
        offset - the offset where the Unicode Decimal value is located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException or IllegalArgumentException may be thrown
        unicodeType - constant value indicating the type of External Decimal
        Returns:
        int the resulting binary integer
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into a long (overflow)
        IllegalArgumentException - if precision or decimalType is invalid, or the digital part of the input is invalid.
      • convertUnicodeDecimalToLong

        public static long convertUnicodeDecimalToLong​(char[] unicodeDecimal,
                                                       int offset,
                                                       int precision,
                                                       boolean checkOverflow,
                                                       int unicodeType)
        Converts a Unicode Decimal value in a char array into a binary long. The sign of the input Unicode Decimal is assumed to be positive unless the sign char contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary long. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        unicodeDecimal - char array which contains the External Decimal value
        offset - offset of the first byte of the Unicode Decimal in unicodeDecimal
        precision - number of Unicode Decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown when
        unicodeType - constant value indicating the type of External Decimal
        Returns:
        long the resulting binary long value
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result does not fit into a long (overflow)
        IllegalArgumentException - if unicodeType or precision is invalid, or the digital part of the input is invalid.
      • convertUnicodeDecimalToPackedDecimal

        public static void convertUnicodeDecimalToPackedDecimal​(char[] unicodeDecimal,
                                                                int unicodeOffset,
                                                                byte[] packedDecimal,
                                                                int packedOffset,
                                                                int precision,
                                                                int decimalType)
        Converts an Unicode Decimal in a char array to a Packed Decimal in a byte array. If the digital part of the input Unicode Decimal is not valid then the digital part of the output will not be valid. The sign of the input Unicode Decimal is assumed to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative.
        Parameters:
        unicodeDecimal - char array that holds the Unicode Decimal to be converted
        unicodeOffset - offset in unicodeDecimal at which the Unicode Decimal is located
        packedDecimal - byte array that will hold the Packed Decimal on a successful return
        packedOffset - offset in packedDecimal where the Packed Decimal is expected to be located
        precision - number of decimal digits
        decimalType - constant value indicating the type of External Decimal
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if packedDecimal or unicodeDecimal are null
        IllegalArgumentException - if precision or decimalType is invalid
      • convertUnicodeDecimalToBigInteger

        public static BigInteger convertUnicodeDecimalToBigInteger​(char[] unicodeDecimal,
                                                                   int offset,
                                                                   int precision,
                                                                   boolean checkOverflow,
                                                                   int decimalType)
        Convert a Unicode Decimal in a char array to a BigInteger. The sign of the input Unicode Decimal is assumed to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary long. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        unicodeDecimal - char array that holds the Packed Decimal to be converted
        offset - offset into unicodeDecimal where the Packed Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value indicating the type of External Decimal
        Returns:
        BigInteger the resulting BigInteger
        Throws:
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        NullPointerException - if unicodeDecimal is null
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if decimalType or precision is invalid, or the digital part of the input is invalid.
      • convertUnicodeDecimalToBigDecimal

        public static BigDecimal convertUnicodeDecimalToBigDecimal​(char[] unicodeDecimal,
                                                                   int offset,
                                                                   int precision,
                                                                   int scale,
                                                                   boolean checkOverflow,
                                                                   int decimalType)
        Converts a Unicode Decimal in a char array to a BigDecimal. The sign of the input Unicode Decimal is assumed to to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into the BigDecimal. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        unicodeDecimal - char array that holds the Unicode Decimal
        offset - offset in unicodeDecimal where the Unicode Decimal is located
        precision - number of decimal digits. Maximum valid precision is 253
        scale - scale of the returned BigDecimal
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value indicating the type of External Decimal
        Returns:
        BigDecimal
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if checkOverflow is true and the Packed Decimal is in an invalid format, or the digital part of the input is invalid.
      • convertBigIntegerToPackedDecimal

        public static void convertBigIntegerToPackedDecimal​(BigInteger bigIntegerValue,
                                                            byte[] packedDecimal,
                                                            int offset,
                                                            int precision,
                                                            boolean checkOverflow)
        Converts a BigInteger value into a Packed Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigIntegerValue - BigInteger value to be converted
        packedDecimal - byte array which will hold the Packed Decimal on a successful return
        offset - offset into packedDecimal where the Packed Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253s
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        Throws:
        NullPointerException - if packedDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
      • convertBigIntegerToExternalDecimal

        public static void convertBigIntegerToExternalDecimal​(BigInteger bigIntegerValue,
                                                              byte[] externalDecimal,
                                                              int offset,
                                                              int precision,
                                                              boolean checkOverflow,
                                                              int decimalType)
        Converts a BigInteger value into an External Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigIntegerValue - BigInteger value to be converted
        externalDecimal - byte array which will hold the External Decimal on a successful return
        offset - offset into externalDecimal where the External Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value that indicates the type of External Decimal
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if decimalType or precision is invalid
      • convertBigIntegerToUnicodeDecimal

        public static void convertBigIntegerToUnicodeDecimal​(BigInteger bigIntegerValue,
                                                             char[] unicodeDecimal,
                                                             int offset,
                                                             int precision,
                                                             boolean checkOverflow,
                                                             int decimalType)
        Converts a BigInteger value to a Unicode Decimal in a char array Overflow can happen if the BigInteger does not fit into the char array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigIntegerValue - BigInteger value to be converted
        unicodeDecimal - char array that will hold the Unicode decimal on a successful return
        offset - offset into unicodeDecimal where the Unicode Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant indicating the type of External Decimal
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if decimalType or precision is invalid
      • convertBigDecimalToPackedDecimal

        public static void convertBigDecimalToPackedDecimal​(BigDecimal bigDecimalValue,
                                                            byte[] packedDecimal,
                                                            int offset,
                                                            int precision,
                                                            boolean checkOverflow)
        Converts a BigDecimal into a Packed Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigDecimalValue - the BigDecimal value to be converted
        packedDecimal - byte array which will hold the Packed Decimal on a successful return
        offset - desired offset in packedDecimal where the Packed Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        Throws:
        NullPointerException - if packedDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
      • convertBigDecimalToExternalDecimal

        public static void convertBigDecimalToExternalDecimal​(BigDecimal bigDecimalValue,
                                                              byte[] externalDecimal,
                                                              int offset,
                                                              int precision,
                                                              boolean checkOverflow,
                                                              int decimalType)
        Converts a BigDecimal value to an External Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigDecimalValue - BigDecimal value to be converted
        externalDecimal - byte array that will hold the External Decimal on a successful return
        offset - offset in externalDecimal where the External Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value indicating the External Decimal type
        Throws:
        NullPointerException - if externalDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if precision or decimalType is invalid
      • convertBigDecimalToUnicodeDecimal

        public static void convertBigDecimalToUnicodeDecimal​(BigDecimal bigDecimalValue,
                                                             char[] unicodeDecimal,
                                                             int offset,
                                                             int precision,
                                                             boolean checkOverflow,
                                                             int decimalType)
        Converts a BigDecimal value to a Unicode Decimal in a char array Overflow can happen if the BigDecimal does not fit into the result char array. In this case, when checkOverflow is true an ArithmeticException is thrown, when false a truncated or invalid result is returned.
        Parameters:
        bigDecimalValue - BigDecimal value to be converted
        unicodeDecimal - char array which will hold the Unicode Decimal on a successful return
        offset - offset in unicodeDecimal where the Unicode Decimal is expected to be located
        precision - number of decimal digits. Maximum valid precision is 253
        checkOverflow - if true an ArithmeticException will be thrown if the decimal value does not fit in the specified precision (overflow)
        decimalType - constant value that indicates the type of External Decimal
        Throws:
        NullPointerException - if unicodeDecimal is null
        ArrayIndexOutOfBoundsException - if an invalid array access occurs
        ArithmeticException - if checkOverflow is true and the result overflows
        IllegalArgumentException - if decimalType or precision is invalid