- java.lang.Object
-
- com.ibm.dataaccess.PackedDecimal
-
public final class PackedDecimal extends Object
Arithmetic, copying and shifting operations for Packed Decimal data.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Add two Packed Decimals in byte arrays.static int
checkPackedDecimal(byte[] byteArray, int offset, int precision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal.static int
checkPackedDecimal(byte[] byteArray, int offset, int precision, boolean ignoreHighNibbleForEvenPrecision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal.static int
checkPackedDecimal(byte[] byteArray, int offset, int precision, boolean ignoreHighNibbleForEvenPrecision, boolean canOverwriteHighNibbleForEvenPrecision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal.static void
dividePackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Divides two Packed Decimals is byte arrays.static boolean
equalsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the two Packed Decimal operands are equal.static boolean
greaterThanOrEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is greater than or equal to the second one.static boolean
greaterThanPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is greater than the second one.static boolean
lessThanOrEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is less than or equal to the second one.static boolean
lessThanPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is lesser than the second one.static void
movePackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, boolean checkOverflow)
Creates a copy of a Packed Decimal.static void
multiplyPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Multiplies two Packed Decimals in byte arrays.static boolean
notEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the two Packed Decimal operands are unequal.static void
remainderPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Calculates the remainder resulting from the division of two Packed Decimals in byte arrays.static void
setPackedZero(byte[] byteArray, int offset, int len)
Create a positive Packed Decimal representation of zero.static void
shiftLeftPackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, int shiftAmount, boolean checkOverflow)
Left shift a Packed Decimal appending zeros to the right.static void
shiftRightPackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, int shiftAmount, boolean round, boolean checkOverflow)
Right shift, and optionally round, a Packed Decimal.static void
subtractPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Subtracts two Packed Decimals in byte arrays.
-
-
-
Method Detail
-
checkPackedDecimal
public static int checkPackedDecimal(byte[] byteArray, int offset, int precision, boolean ignoreHighNibbleForEvenPrecision, boolean canOverwriteHighNibbleForEvenPrecision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal.- Parameters:
byteArray
- the source container arrayoffset
- starting offset of the Packed Decimalprecision
- precision of the Packed Decimal. Maximum valid precision is 253ignoreHighNibbleForEvenPrecision
- if true, ignore to check if the top nibble (first 4 bits) of the input is an invalid sign value in the case of even precisioncanOverwriteHighNibbleForEvenPrecision
- if true, change the high nibble to a zero in case of even precision- Returns:
- the condition code: 0 All digit codes and the sign valid 1 Sign invalid 2 At least one digit code invalid 3 Sign invalid and at least one digit code invalid
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
checkPackedDecimal
public static int checkPackedDecimal(byte[] byteArray, int offset, int precision, boolean ignoreHighNibbleForEvenPrecision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal. The most significant nibble cannot be overwritten.- Parameters:
byteArray
- the source container arrayoffset
- starting offset of the Packed Decimalprecision
- precision of the Packed DecimalignoreHighNibbleForEvenPrecision
- if true, ignore the high nibble in the case of even precision- Returns:
- the condition code: 0 All digit codes and the sign valid 1 Sign invalid 2 At least one digit code invalid 3 Sign invalid and at least one digit code invalid
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
checkPackedDecimal
public static int checkPackedDecimal(byte[] byteArray, int offset, int precision)
Checks the validity of a Packed Decimal, return code indicating the status of the Packed Decimal. Don't ignore the most significant nibble. The most significant nibble cannot be overwritten.- Parameters:
byteArray
- the source container arrayoffset
- starting offset of the Packed Decimalprecision
- precision of the Packed Decimal- Returns:
- the condition code: 0 All digit codes and the sign valid 1 Sign invalid 2 At least one digit code invalid 3 Sign invalid and at least one digit code invalid
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
addPackedDecimal
public static void addPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow) throws ArithmeticException
Add two Packed Decimals in byte arrays. The sign of an 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 respective input Packed Decimal is interpreted as negative.- Parameters:
result
- byte array that will hold the sum of the two operand Packed DecimalsresultOffset
- offset intoresult
where the sum Packed Decimal beginsresultPrecision
- number of Packed Decimal digits for the sum. Maximum valid precision is 253op1Decimal
- byte array that holds the first operand Packed Decimal.op1Offset
- offset intoop1Decimal
where the Packed Decimal. is locatedop1Precision
- number of Packed Decimal digits for the first operand. Maximum valid precision is 253op2Decimal
- byte array that holds the second operand Packed Decimalop2Offset
- offset intoop2Decimal
where the Packed Decimal is locatedop2Precision
- number of Packed Decimal digits for the second operand. Maximum valid precision is 253checkOverflow
- check for overflow- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursArithmeticException
- if an overflow occurs during the computation of the sum
-
subtractPackedDecimal
public static void subtractPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow) throws ArithmeticException
Subtracts two Packed Decimals in byte arrays. The sign of an 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 respective input Packed Decimal is interpreted as negative.- Parameters:
result
- byte array that will hold the difference of the two operand Packed DecimalsresultOffset
- offset intoresult
where the result Packed Decimal is locatedresultPrecision
- number of Packed Decimal digits for the result. Maximum valid precision is 253op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operand. Maximum valid precision is 253op2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand. Maximum valid precision is 253checkOverflow
- check for overflow- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursArithmeticException
- if an overflow occurs during the computation of the difference
-
setPackedZero
public static void setPackedZero(byte[] byteArray, int offset, int len)
Create a positive Packed Decimal representation of zero.- Parameters:
byteArray
- byte array which will hold the packed zerooffset
- offset intotoBytes
where the packed zero beginslen
- length of the packed zero. Maximum valid length is 253- Throws:
NullPointerException
- iftoBytes
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
multiplyPackedDecimal
public static void multiplyPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Multiplies two Packed Decimals in byte arrays. The sign of an 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 respective input Packed Decimal is interpreted as negative.- Parameters:
result
- byte array that will hold the product Packed DecimalresultOffset
- offset intoresult
where the product Packed Decimal is locatedresultPrecision
- the length (number of digits) of the product Packed Decimal. Maximum valid precision is 253op1Decimal
- byte array that will hold the multiplicand Packed Decimalop1Offset
- offset intoop1Decimal
where the multiplicand is locatedop1Precision
- the length (number of digits) of the multiplicand Packed Decimal. Maximum valid precision is 253op2Decimal
- byte array that will hold the multiplierop2Offset
- offset intoop2Decimal
where the multiplier is locatedop2Precision
- the length (number of digits) of the multiplier Packed Decimal. Maximum valid precision is 253checkOverflow
- if set to true, Packed Decimals are validated before multiplication and anIllegalArgumentException
orArithmeticException
may be thrown. If not, the result can be invalid- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursIllegalArgumentException
- if an overflow occurs during multiplicationArithmeticException
- if any of the Packed Decimal operands are invalid
-
dividePackedDecimal
public static void dividePackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Divides two Packed Decimals is byte arrays. The sign of an 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 respective input Packed Decimal is interpreted as negative.- Parameters:
result
- byte array that will hold the quotient Packed DecimalresultOffset
- offset intoresult
where the quotient Packed Decimal is locatedresultPrecision
- the length (number of digits) of the quotient Packed Decimal. Maximum valid precision is 253op1Decimal
- byte array that will hold the dividend Packed Decimalop1Offset
- offset intoop1Decimal
where the dividend is locatedop1Precision
- the length (number of digits) of the dividend Packed Decimal. Maximum valid precision is 253op2Decimal
- byte array that will hold the divisorop2Offset
- offset intoop2Decimal
where the divisor is locatedop2Precision
- the length (number of digits) of the divisor Packed Decimal. Maximum valid precision is 253checkOverflow
- if set to true, Packed Decimals are validated before division and anIllegalArgumentException
orArithmeticException
may be thrown. If not, the result can be invalid- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursIllegalArgumentException
- if an overflow occurs during divisionArithmeticException
- if any of the Packed Decimal operands are invalid
-
remainderPackedDecimal
public static void remainderPackedDecimal(byte[] result, int resultOffset, int resultPrecision, byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision, boolean checkOverflow)
Calculates the remainder resulting from the division of two Packed Decimals in byte arrays. The sign of an 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 respective input Packed Decimal is interpreted as negative.- Parameters:
result
- byte array that will hold the remainder Packed DecimalresultOffset
- offset intoresult
where the remainder Packed Decimal is locatedresultPrecision
- number of Packed Decimal digits for the remainder. Maximum valid precision is 253op1Decimal
- byte array that will hold the dividend Packed Decimalop1Offset
- offset intoop1Decimal
where the dividend is locatedop1Precision
- number of Packed Decimal digits for the dividend. Maximum valid precision is 253op2Decimal
- byte array that will hold the divisorop2Offset
- offset intoop2Decimal
where the divisor is locatedop2Precision
- number of Packed Decimal digits for the divisor. Maximum valid precision is 253checkOverflow
- if set to true, Packed Decimals are validated before division and anIllegalArgumentException
orArithmeticException
may be thrown. If not, the result can be invalid- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursIllegalArgumentException
- if an overflow occurs during divisionArithmeticException
- if any of the Packed Decimal operands are invalid
-
lessThanPackedDecimal
public static boolean lessThanPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is lesser than the second one.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if
op1Decimal < op2Decimal
, false otherwise - Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
lessThanOrEqualsPackedDecimal
public static boolean lessThanOrEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is less than or equal to the second one.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if
op1Decimal <= op2Decimal
, false otherwise - Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
greaterThanPackedDecimal
public static boolean greaterThanPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is greater than the second one.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if
op1Decimal > op2Decimal
, false otherwise - Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
greaterThanOrEqualsPackedDecimal
public static boolean greaterThanOrEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the first Packed Decimal operand is greater than or equal to the second one.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if
op1Decimal >= op2Decimal
, false otherwise - Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
equalsPackedDecimal
public static boolean equalsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the two Packed Decimal operands are equal.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if op1Decimal == op2Decimal, false otherwise
- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
notEqualsPackedDecimal
public static boolean notEqualsPackedDecimal(byte[] op1Decimal, int op1Offset, int op1Precision, byte[] op2Decimal, int op2Offset, int op2Precision)
Checks if the two Packed Decimal operands are unequal.- Parameters:
op1Decimal
- byte array that holds the first Packed Decimal operandop1Offset
- offset intoop1Decimal
where the first operand is locatedop1Precision
- number of Packed Decimal digits for the first operandop2Decimal
- byte array that holds the second Packed Decimal operandop2Offset
- offset intoop2Decimal
where the second operand is locatedop2Precision
- number of Packed Decimal digits for the second operand- Returns:
- true if op1Decimal != op2Decimal, false otherwise
- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
shiftRightPackedDecimal
public static void shiftRightPackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, int shiftAmount, boolean round, boolean checkOverflow)
Right shift, and optionally round, a Packed Decimal. If the resultant is zero, it can either be a positive zero 0x0C or a negative zero 0x0D.- Parameters:
destination
- byte array that holds the result of the right shift (and rounding)destinationOffset
- offset intodestination
where the result Packed Decimal is locateddestinationPrecision
- number of Packed Decimal digits in the destinationsource
- byte array that holds the Packed Decimal operand to be right shiftedsourceOffset
- offset intosource
where the operand is locatedsourcePrecision
- number of Packed Decimal digits in the operandshiftAmount
- amount by which the source will be right shiftedround
- if set to true, causes rounding to occurcheckOverflow
- if set to true, check for overflow- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursArithmeticException
- if a decimal overflow occursIllegalArgumentException
- if theshiftAmount
orsourcePrecision
parameter is invalid or thesource
packed decimal contains invalid sign or digit code
-
shiftLeftPackedDecimal
public static void shiftLeftPackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, int shiftAmount, boolean checkOverflow)
Left shift a Packed Decimal appending zeros to the right. In the absence of overflow, the sign of a zero can either be positive 0x0C or negative 0x0D.- Parameters:
destination
- byte array that holds the result of the left shiftdestinationOffset
- offset intodestination
where the result Packed Decimal is locateddestinationPrecision
- number of Packed Decimal digits in the destinationsource
- byte array that holds the Packed Decimal operand to be left shiftedsourceOffset
- offset intosource
where the operand is locatedsourcePrecision
- number of Packed Decimal digits in the operandshiftAmount
- amount by which the source will be left shiftedcheckOverflow
- if set to true, check for overflow- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursArithmeticException
- if a decimal overflow occursIllegalArgumentException
- if theshiftAmount
orsourcePrecision
parameter is invalid or thesource
packed decimal contains invalid sign or digit code
-
movePackedDecimal
public static void movePackedDecimal(byte[] destination, int destinationOffset, int destinationPrecision, byte[] source, int sourceOffset, int sourcePrecision, boolean checkOverflow)
Creates a copy of a Packed Decimal.- Parameters:
destination
- byte array representing the destinationdestinationOffset
- offset into destinationdestination
where the Packed Decimal is locateddestinationPrecision
- number of Packed Decimal digits for the destinationsource
- byte array which holds the source Packed DecimalsourceOffset
- offset intosource
where the Packed Decimal is locatedsourcePrecision
- number of Packed Decimal digits for the source. Maximum valid precision is 253checkOverflow
- if set to true, moved Packed Decimals are validated, and anIllegalArgumentException
orArithmeticException
is thrown if non-zero nibbles are truncated during the move operation. If set to false, no validating is conducted.- Throws:
NullPointerException
- if any of the byte arrays are nullArrayIndexOutOfBoundsException
- if an invalid array access occursIllegalArgumentException
- if the source Packed Decimal is invalidArithmeticException
- if a decimal overflow occurs
-
-