gishur.core.math
Class DoubleNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--gishur.core.math.MathNumber
              |
              +--gishur.core.math.DoubleNumber
All Implemented Interfaces:
java.io.Serializable

public class DoubleNumber
extends MathNumber

A wrapper for double values based upon MathNumber. DoubleNumber simply wraps a double value - like Double, but it too supports all arithmetic operations defined at MathNumber. Because Double is a final class, DoubleNumber cannot extend Double, only Number.

Version:
1.0
Author:
Thomas Wolf
See Also:
Serialized Form

Fields inherited from class gishur.core.math.MathNumber
MINUS_ONE, ONE, ZERO
 
Constructor Summary
DoubleNumber(double d)
          Default Constructor.
DoubleNumber(DoubleNumber d)
          Copy Constructor.
 
Method Summary
 MathNumber abs()
          Computes |this|.
 MathNumber add(MathNumber n)
          Computes this+n.
 int compareTo(MathNumber n)
          Returns -1, 0 or 1 as this number is less than, equal to, or greater than n.
 MathNumber divide(MathNumber n)
          Computes this/n.
 double doubleValue()
          Returns the value of the number as a double.
 MathNumber invert()
          Computes 1/this.
 MathNumber log()
          Returns the natural logarithm (base e) of this MathNumber.
 MathNumber multiply(MathNumber n)
          Computes this*n.
 MathNumber negate()
          Computes -this.
 MathNumber pow(long n)
          Computes this^n.
 int sign()
          Determines the sign of this number.
 MathNumber sqrt()
          Computes the square root of this.
 MathNumber subtract(MathNumber n)
          Computes this-n.
 
Methods inherited from class gishur.core.math.MathNumber
byteValue, floatValue, intValue, longValue, max, min, shortValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DoubleNumber

public DoubleNumber(double d)
Default Constructor.

DoubleNumber

public DoubleNumber(DoubleNumber d)
Copy Constructor.
Method Detail

sign

public int sign()
Determines the sign of this number. This method returns -1, 0, or 1 as this number is negative, zero, or positive.
Overrides:
sign in class MathNumber
Returns:
the sign of this number.
See Also:
RationalNumber

compareTo

public int compareTo(MathNumber n)
Returns -1, 0 or 1 as this number is less than, equal to, or greater than n.
Overrides:
compareTo in class MathNumber
Parameters:
n - the number to compare to.
Returns:
-1 if this<n, 0 if this==n, 1 if this>n.
Throws:
java.lang.IllegalArgumentException - if the argument is null.

abs

public MathNumber abs()
Computes |this|.
Overrides:
abs in class MathNumber
Returns:
the absolute of this.

negate

public MathNumber negate()
Computes -this.
Overrides:
negate in class MathNumber
Returns:
the negative of this.

invert

public MathNumber invert()
Computes 1/this.
Overrides:
invert in class MathNumber
Returns:
result.
Throws:
ArithmeticException - if the value of this number is zero.

add

public MathNumber add(MathNumber n)
Computes this+n.
Overrides:
add in class MathNumber
Parameters:
n - the number to add to this.
Returns:
the sum of this and n.
Throws:
MathNumberException - if the operation does not support the type of n.

subtract

public MathNumber subtract(MathNumber n)
Computes this-n.
Overrides:
subtract in class MathNumber
Parameters:
n - the number to subtract from this.
Returns:
this minus n.
Throws:
MathNumberException - if the operation does not support the type of n.

multiply

public MathNumber multiply(MathNumber n)
Computes this*n.
Overrides:
multiply in class MathNumber
Parameters:
n - the number to multiply this by.
Returns:
the product of this and n.
Throws:
MathNumberException - if the operation does not support the type of n.

divide

public MathNumber divide(MathNumber n)
Computes this/n.
Overrides:
divide in class MathNumber
Parameters:
n - the number to divide this by.
Returns:
this divided by n.
Throws:
MathNumberException - if the operation does not support the type of n.
ArithmeticException - if the argument is zero.

pow

public MathNumber pow(long n)
Computes this^n.
Overrides:
pow in class MathNumber
Parameters:
n - the exponent.
Returns:
this raised to the power of n.
Throws:
MathNumberException - if this Method is not supported or if the argument is null.

log

public MathNumber log()
Returns the natural logarithm (base e) of this MathNumber.
Overrides:
log in class MathNumber
Returns:
Natural logarithm
Throws:
java.lang.IllegalArgumentException - if the argument is less than 0.
MathNumberException - if this Method is not supported

sqrt

public MathNumber sqrt()
Computes the square root of this.
Overrides:
sqrt in class MathNumber
Returns:
square root of this.
Throws:
java.lang.IllegalArgumentException - if the argument is less than 0.
MathNumberException - if this Method is not supported

doubleValue

public double doubleValue()
Returns the value of the number as a double.
Overrides:
doubleValue in class MathNumber
Returns:
number as double