com.ibm.eou.decimal
Class ModelNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--com.ibm.eou.decimal.ModelNumber
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class ModelNumber
extends java.lang.Number
implements java.lang.Comparable

This class represents a generic floating-point number, with almost no limitation on precision or magnitude, and also includes some special values. Finite numbers are represented as a sign, a finite-length coefficient expressed as a string of digits in a given radix, and a signed integer exponent. The coefficient length is limited only by storage, and the exponent is limited only to values which can be stored by a Java 'int' type. Infinities can also have a sign, and two not-a-number (NaN) values (quiet and signaling) are also supported.

Author:
Dave Clark, IBM Ease of Use
See Also:
Serialized Form

Field Summary
static ModelNumber NAN
          A ModelNumber representing a (quiet) NaN.
static ModelNumber NEGATIVE_INFINITY
          A ModelNumber representing a negative infinity.
static ModelNumber POSITIVE_INFINITY
          A ModelNumber representing a positive infinity.
static ModelNumber SIGNALING_NAN
          A ModelNumber representing a signaling NaN.
 
Method Summary
 byte byteValue()
           
 int compareTo(java.lang.Object o)
           
static ModelNumber createFinite(int sign, int radix, int[] coefficient, int exponent)
          Return a ModelNumber representing a finite number.
static ModelNumber createFinite(int sign, int radix, java.lang.String coefficient, int exponent)
          Return a ModelNumber representing a finite number.
 double doubleValue()
           
 boolean equals(java.lang.Object obj)
          Return true if the supplied argument is a ModelNumber equal to this ModelNumber.
 float floatValue()
           
 int[] getCoefficient()
          Return the coefficient digit values.
 java.lang.String getCoefficientAsString()
          Return the coefficient as a string of digit characters.
 int getExponent()
          Return the exponent.
 int getRadix()
          Return the radix in which the coefficient is expressed.
 int getSign()
          Return the sign of the value.
 int hashCode()
          Return a hash code generated so that two ModelNumbers which compare equal with equals will always produce the same hash code, and ModelNumbers which do not compare equal with equals tend to (but will not necessarily) produce different hash codes.
 int intValue()
           
 boolean isFinite()
          Return true if the value is finite.
 boolean isInfinity()
          Return true if the value is an infinity.
 boolean isNaN()
          Return true if the value is a quiet NaN.
 boolean isSignalingNaN()
          Return true if the value is a signaling NaN.
 boolean isZero()
          Return true if the value is a zero.
 long longValue()
           
static int parseDigit(char digit)
           
 short shortValue()
           
 java.lang.String toString()
          Return a string representation of the internal fields of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NAN

public static final ModelNumber NAN
A ModelNumber representing a (quiet) NaN.

See Also:
SIGNALING_NAN

SIGNALING_NAN

public static final ModelNumber SIGNALING_NAN
A ModelNumber representing a signaling NaN.

See Also:
NAN

POSITIVE_INFINITY

public static final ModelNumber POSITIVE_INFINITY
A ModelNumber representing a positive infinity.


NEGATIVE_INFINITY

public static final ModelNumber NEGATIVE_INFINITY
A ModelNumber representing a negative infinity.

Method Detail

createFinite

public static ModelNumber createFinite(int sign,
                                       int radix,
                                       int[] coefficient,
                                       int exponent)
Return a ModelNumber representing a finite number. The number is specified as a sign (0=positive, 1=negative), a radix, a coefficient comprising digit values in the range zero to radix-1, and a signed integer exponent.

Parameters:
sign - the sign (0=positive, 1=negative).
radix - the radix in which the coefficient is expressed.
coefficient - the coefficient.
exponent - the signed integer exponent.
Returns:
a ModelNumber representing the finite number.

createFinite

public static ModelNumber createFinite(int sign,
                                       int radix,
                                       java.lang.String coefficient,
                                       int exponent)
Return a ModelNumber representing a finite number. The number is specified as a sign (0=positive, 1=negative), a radix, a coefficient comprising digit characters '0'-'9','A'-'Z' (as required) and a signed integer exponent.

Parameters:
sign - the sign (0=positive, 1=negative).
radix - the radix in which the coefficient is expressed.
coefficient - the coefficient.
exponent - the signed integer exponent.
Returns:
a ModelNumber representing the finite number.

parseDigit

public static int parseDigit(char digit)

isNaN

public boolean isNaN()
Return true if the value is a quiet NaN.


isSignalingNaN

public boolean isSignalingNaN()
Return true if the value is a signaling NaN.


isInfinity

public boolean isInfinity()
Return true if the value is an infinity. Infinities also have a sign.

See Also:
getSign()

isFinite

public boolean isFinite()
Return true if the value is finite. Finite numbers also have a sign, a radix, a coefficient, and an exponent.

See Also:
getSign(), getRadix(), getCoefficient(), getExponent()

isZero

public boolean isZero()
Return true if the value is a zero.


getSign

public int getSign()
Return the sign of the value. A sign of 0 is positive and 1 is negative.


getRadix

public int getRadix()
Return the radix in which the coefficient is expressed.


getCoefficient

public int[] getCoefficient()
Return the coefficient digit values.


getCoefficientAsString

public java.lang.String getCoefficientAsString()
Return the coefficient as a string of digit characters.


getExponent

public int getExponent()
Return the exponent.


byteValue

public byte byteValue()
Overrides:
byteValue in class java.lang.Number
See Also:
Number.byteValue()

doubleValue

public double doubleValue()
Specified by:
doubleValue in class java.lang.Number
See Also:
Number.doubleValue()

floatValue

public float floatValue()
Specified by:
floatValue in class java.lang.Number
See Also:
Number.floatValue()

intValue

public int intValue()
Specified by:
intValue in class java.lang.Number
See Also:
Number.intValue()

longValue

public long longValue()
Specified by:
longValue in class java.lang.Number
See Also:
Number.longValue()

shortValue

public short shortValue()
Overrides:
shortValue in class java.lang.Number
See Also:
Number.shortValue()

toString

public java.lang.String toString()
Return a string representation of the internal fields of this object.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Return true if the supplied argument is a ModelNumber equal to this ModelNumber. Note that only exact equality is detected: different representations of numerically equivalent values will compare as different.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Return a hash code generated so that two ModelNumbers which compare equal with equals will always produce the same hash code, and ModelNumbers which do not compare equal with equals tend to (but will not necessarily) produce different hash codes.

Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable
See Also:
Comparable.compareTo(Object)