ewe.math
Class BigDecimal

java.lang.Object
  extended byewe.math.Number
      extended byewe.math.BigDecimal
All Implemented Interfaces:
ByteEncodable, Comparable

public class BigDecimal
extends Number
implements Comparable, ByteEncodable


Field Summary
static int ROUND_CEILING
           
static int ROUND_DOWN
           
static int ROUND_FLOOR
           
static int ROUND_HALF_DOWN
           
static int ROUND_HALF_EVEN
           
static int ROUND_HALF_UP
           
static int ROUND_UNNECESSARY
           
static int ROUND_UP
           
 
Fields inherited from class ewe.math.Number
DOUBLE_MAX_VALUE, DOUBLE_MIN_VALUE, INTEGER_MAX_VALUE, INTEGER_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NEGATIVE_INFINITY, POSITIVE_INFINITY
 
Constructor Summary
BigDecimal(BigInteger num)
           
BigDecimal(BigInteger num, int scale)
           
BigDecimal(byte[] data)
           
BigDecimal(byte[] data, int offset, int length)
          Create a new BigDecimal from a byte array.
BigDecimal(double num)
           
BigDecimal(String num)
           
 
Method Summary
 BigDecimal abs()
           
 BigDecimal add(BigDecimal val)
           
static int compareEncoded(byte[] one, int oneOffset, int oneLen, byte[] two, int twoOffset, int twoLen)
           
 int compareTo(BigDecimal val)
           
 int compareTo(Object val)
          Compare this object with another.
 BigDecimal divide(BigDecimal val, int roundingMode)
           
 BigDecimal divide(BigDecimal val, int newScale, int roundingMode)
           
 double doubleValue()
          Return the value of this Number as a double.
 int encodeBytes(ByteArray dest)
          This requests the Object to encode itself as a stream of bytes which is appended to the destination ByteArray.
 boolean equals(Object o)
          Returns if this object is considered equal to the other object.
 float floatValue()
          Return the value of this Number as a float.
 int hashCode()
          Returns a hashCode for the object.
 int intValue()
          Return the value of this Number as an int.
 long longValue()
          Return the value of this Number as a long.
 BigDecimal max(BigDecimal val)
           
 BigDecimal min(BigDecimal val)
           
 BigDecimal movePointLeft(int n)
           
 BigDecimal movePointRight(int n)
           
 BigDecimal multiply(BigDecimal val)
           
 BigDecimal negate()
           
 int scale()
           
 BigDecimal setScale(int scale)
           
 BigDecimal setScale(int scale, int roundingMode)
           
 int signum()
           
 BigDecimal subtract(BigDecimal val)
           
 BigInteger toBigInteger()
           
 byte[] toByteArray()
           
 String toString()
          Return a String representation of this object.
 BigInteger unscaledValue()
           
static BigDecimal valueOf(long val)
           
static BigDecimal valueOf(long val, int scale)
           
 int write(byte[] data, int offset)
          Write the BigDecimal as a series of bytes, or find out how many bytes are needed for storing the BigDecimal.
 
Methods inherited from class ewe.math.Number
byteValue, digit, forDigit, isInfinite, isNaN, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass
 

Field Detail

ROUND_UP

public static final int ROUND_UP
See Also:
Constant Field Values

ROUND_DOWN

public static final int ROUND_DOWN
See Also:
Constant Field Values

ROUND_CEILING

public static final int ROUND_CEILING
See Also:
Constant Field Values

ROUND_FLOOR

public static final int ROUND_FLOOR
See Also:
Constant Field Values

ROUND_HALF_UP

public static final int ROUND_HALF_UP
See Also:
Constant Field Values

ROUND_HALF_DOWN

public static final int ROUND_HALF_DOWN
See Also:
Constant Field Values

ROUND_HALF_EVEN

public static final int ROUND_HALF_EVEN
See Also:
Constant Field Values

ROUND_UNNECESSARY

public static final int ROUND_UNNECESSARY
See Also:
Constant Field Values
Constructor Detail

BigDecimal

public BigDecimal(BigInteger num)

BigDecimal

public BigDecimal(BigInteger num,
                  int scale)
           throws NumberFormatException

BigDecimal

public BigDecimal(double num)
           throws NumberFormatException

BigDecimal

public BigDecimal(String num)
           throws NumberFormatException

BigDecimal

public BigDecimal(byte[] data,
                  int offset,
                  int length)
Create a new BigDecimal from a byte array.

Parameters:
data - the data to read.
offset - the start of the data.
length - the number of bytes of encoded data.

BigDecimal

public BigDecimal(byte[] data)
Method Detail

valueOf

public static BigDecimal valueOf(long val)

valueOf

public static BigDecimal valueOf(long val,
                                 int scale)
                          throws NumberFormatException
Throws:
NumberFormatException

add

public BigDecimal add(BigDecimal val)

subtract

public BigDecimal subtract(BigDecimal val)

multiply

public BigDecimal multiply(BigDecimal val)

divide

public BigDecimal divide(BigDecimal val,
                         int roundingMode)
                  throws ArithmeticException,
                         IllegalArgumentException
Throws:
ArithmeticException
IllegalArgumentException

divide

public BigDecimal divide(BigDecimal val,
                         int newScale,
                         int roundingMode)
                  throws ArithmeticException,
                         IllegalArgumentException
Throws:
ArithmeticException
IllegalArgumentException

compareTo

public int compareTo(BigDecimal val)

compareTo

public int compareTo(Object val)
Description copied from interface: Comparable
Compare this object with another. It should return: less than 0 if this object is considered LESS than the "other" object; greater than 0 if this object is considered GREATER than the "other" object; 0 if this object is considered EQUAL to the "other" object. (i.e. it is an implicit subtraction).

Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object o)
Description copied from class: Object
Returns if this object is considered equal to the other object.

Overrides:
equals in class Object
Parameters:
o - Another object to compare to.
Returns:
true if this object is considered equal to the other object.

hashCode

public int hashCode()
Description copied from class: Object
Returns a hashCode for the object. The general contract of hashCode is:
  • An object must return the same hash code for its entire existence.
  • If two objects are considered equal by the equals() method, they should return the same hash code. Not all Objects will do this and you should only use hashCode() from Objects which declare an overrided version of hashCode(). The only Objects which provide consistent and correct hash codes under Ewe are Object, String and Class.

    Overrides:
    hashCode in class Object

  • max

    public BigDecimal max(BigDecimal val)

    min

    public BigDecimal min(BigDecimal val)

    movePointLeft

    public BigDecimal movePointLeft(int n)

    movePointRight

    public BigDecimal movePointRight(int n)

    signum

    public int signum()

    scale

    public int scale()

    unscaledValue

    public BigInteger unscaledValue()

    abs

    public BigDecimal abs()

    negate

    public BigDecimal negate()

    toString

    public String toString()
    Description copied from class: Object
    Return a String representation of this object.

    Overrides:
    toString in class Object
    Returns:
    a String representing this object.

    toBigInteger

    public BigInteger toBigInteger()

    intValue

    public int intValue()
    Description copied from class: Number
    Return the value of this Number as an int.

    Specified by:
    intValue in class Number
    Returns:
    the int value

    longValue

    public long longValue()
    Description copied from class: Number
    Return the value of this Number as a long.

    Specified by:
    longValue in class Number
    Returns:
    the long value

    floatValue

    public float floatValue()
    Description copied from class: Number
    Return the value of this Number as a float.

    Specified by:
    floatValue in class Number
    Returns:
    the float value

    doubleValue

    public double doubleValue()
    Description copied from class: Number
    Return the value of this Number as a double.

    Specified by:
    doubleValue in class Number
    Returns:
    the double value

    setScale

    public BigDecimal setScale(int scale)
                        throws ArithmeticException
    Throws:
    ArithmeticException

    setScale

    public BigDecimal setScale(int scale,
                               int roundingMode)
                        throws ArithmeticException,
                               IllegalArgumentException
    Throws:
    ArithmeticException
    IllegalArgumentException

    write

    public int write(byte[] data,
                     int offset)
    Write the BigDecimal as a series of bytes, or find out how many bytes are needed for storing the BigDecimal.

    Parameters:
    data - The destination byte array or null to find out how many bytes are needed.
    offset - The offset in the byte array to write to.
    Returns:
    The number of bytes written or needed to be written.

    encodeBytes

    public int encodeBytes(ByteArray dest)
    Description copied from interface: ByteEncodable
    This requests the Object to encode itself as a stream of bytes which is appended to the destination ByteArray. If the destination ByteArray is null, then the object should report how many bytes would be used if the object was encoded.

    Specified by:
    encodeBytes in interface ByteEncodable
    Parameters:
    dest - The destination ByteArray, or null to determine the number of bytes needed to encode.
    Returns:
    The number of bytes appended to the ByteArray or the number of bytes needed to encode.

    toByteArray

    public byte[] toByteArray()

    compareEncoded

    public static int compareEncoded(byte[] one,
                                     int oneOffset,
                                     int oneLen,
                                     byte[] two,
                                     int twoOffset,
                                     int twoLen)