com.ibm.eou.decimal
Class DecimalEncoder

java.lang.Object
  |
  +--com.ibm.eou.decimal.DecimalEncoder

public final class DecimalEncoder
extends java.lang.Object

This class provides static library methods for encoding binary representations of decimal floating-point numbers using the decimal32, decimal64 and decimal128 formats.

Author:
Dave Clark, IBM Ease of Use

Method Summary
static BitString encodeDecimal(DecimalConstants.DecimalEncoding encoding, int sign, int[] coefficient, int exponent, DecimalConstants.RoundingMode rounding, ArithmeticConditions flags)
          Return a bit field containing a decimalNNN encoding of a finite numeric value.
static BitString encodeDecimal(DecimalConstants.DecimalEncoding encoding, ModelNumber number, DecimalConstants.RoundingMode rounding, ArithmeticConditions flags)
          Return a bit field containing a decimalNNN encoding of a generic floating-point number.
static BitString encodeFiniteAsDecimal(DecimalConstants.DecimalEncoding encoding, int sign, int[] coefficient, int exponent)
          Return a bit field containing a DecimalNNN encoding of a finite numeric value.
static BitString encodeInfinityAsDecimal(DecimalConstants.DecimalEncoding encoding, int sign)
          Return a bit field containing a DecimalNNN encoding of an infinity value.
static BitString encodeNaNAsDecimal(DecimalConstants.DecimalEncoding encoding)
          Return a bit field containing a DecimalNNN encoding of a (quiet) Not-a-Number value.
static BitString encodeSignalingNaNAsDecimal(DecimalConstants.DecimalEncoding encoding)
          Return a bit field containing a DecimalNNN encoding of a signaling Not-a-Number value.
static ModelNumber toModelNumber(java.lang.String value)
          Return a ModelNumber corresponding to the decimal string representation supplied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encodeNaNAsDecimal

public static BitString encodeNaNAsDecimal(DecimalConstants.DecimalEncoding encoding)
Return a bit field containing a DecimalNNN encoding of a (quiet) Not-a-Number value.

Parameters:
encoding - the encoding to be used.
Returns:
a bit field of 32, 64 or 128 bits according to the decimalNNN format selected.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

encodeSignalingNaNAsDecimal

public static BitString encodeSignalingNaNAsDecimal(DecimalConstants.DecimalEncoding encoding)
Return a bit field containing a DecimalNNN encoding of a signaling Not-a-Number value.

Parameters:
encoding - the encoding to be used.
Returns:
a bit field of 32, 64 or 128 bits according to the decimalNNN format selected.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

encodeInfinityAsDecimal

public static BitString encodeInfinityAsDecimal(DecimalConstants.DecimalEncoding encoding,
                                                int sign)
Return a bit field containing a DecimalNNN encoding of an infinity value.

Parameters:
encoding - the encoding to be used.
sign - +1 or 0 to specify negative or positive infinity.
Returns:
a bit field of 32, 64 or 128 bits according to the decimalNNN format selected.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

encodeFiniteAsDecimal

public static BitString encodeFiniteAsDecimal(DecimalConstants.DecimalEncoding encoding,
                                              int sign,
                                              int[] coefficient,
                                              int exponent)
Return a bit field containing a DecimalNNN encoding of a finite numeric value. This method produces an exact encoding, and the coefficient must have exactly the appropriate length and the exponent must be in the allowed range. This method will not perform any of the adjustments which can allow values to be encoded in numerically equivalent forms that fit the encoding, nor will it perform any rounding or overflow/underflow adjustments. If the sign, coefficient and exponent supplied cannot be encoded in the specified encoding exactly as they are given, then an exception is thrown.

Parameters:
encoding - the encoding to be used.
sign - +1 or 0 to specify a negative or positive number.
coefficient - an array of decimal digit values in the range 0-9, with a length of 7 (for decimal32), 16 (for decimal64) or 34 (for decimal128), and with no leading zeroes (except when the coefficient is all zeroes).
Returns:
a bit field of 32, 64 or 128 bits, according to the decimalNNN format selected, exactly encoding the supplied value.
Throws:
java.lang.IllegalArgumentException - if the supplied value cannot be encoded in the specified encoding exactly as supplied.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

encodeDecimal

public static BitString encodeDecimal(DecimalConstants.DecimalEncoding encoding,
                                      ModelNumber number,
                                      DecimalConstants.RoundingMode rounding,
                                      ArithmeticConditions flags)
Return a bit field containing a decimalNNN encoding of a generic floating-point number. This method may need to adjust the value being encoded, and will set appropriate flags in the supplied conversion flags to indicate what situations occurred.

Parameters:
encoding - the encoding to be used.
number - a floating-point number to encode.
flags - a set of conversion flags which may be set during the generation of the encoded result.
Returns:
a bit field of 32, 64 or 128 bits according to the decimalNNN format selected.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

encodeDecimal

public static BitString encodeDecimal(DecimalConstants.DecimalEncoding encoding,
                                      int sign,
                                      int[] coefficient,
                                      int exponent,
                                      DecimalConstants.RoundingMode rounding,
                                      ArithmeticConditions flags)
Return a bit field containing a decimalNNN encoding of a finite numeric value. This method may need to adjust the value being encoded, and will set appropriate flags in the supplied conversion flags to indicate what situations occurred.

Parameters:
encoding - the encoding to be used.
sign - +1 or 0 to specify a negative or positive number.
coefficient - an array of decimal digits, with no leading zeroes (except when the coefficient is a single zero).
exponent - decimal exponent.
rounding - the rounding mode
flags - a set of conversion flags which may be set during the generation of the encoded result.
Returns:
a bit field of 32, 64 or 128 bits according to the decimalNNN format selected.
See Also:
DecimalConstants.DECIMAL32, DecimalConstants.DECIMAL64, DecimalConstants.DECIMAL128

toModelNumber

public static ModelNumber toModelNumber(java.lang.String value)
Return a ModelNumber corresponding to the decimal string representation supplied.

Returns:
a ModelNumber representing the supplied value.