gishur.core.math
Class MathNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--gishur.core.math.MathNumber
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DoubleNumber, RationalNumber

public abstract class MathNumber
extends java.lang.Number

A abstract number class based upon java.lang.Number. This class extends Number with a couple of arithmetic methods.

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

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

Field Detail

ZERO

public static MathNumber ZERO
The numer 0 as MathNumber.

ONE

public static MathNumber ONE
The numer 1 as MathNumber.

MINUS_ONE

public static MathNumber MINUS_ONE
The numer -1 as MathNumber.
Constructor Detail

MathNumber

public MathNumber()
Method Detail

compareTo

public int compareTo(MathNumber n)
Returns -1, 0 or 1 as this number is less than, equal to, or greater than n.
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.

min

public static MathNumber min(MathNumber n1,
                             MathNumber n2)
Returns the Minimum of the both MathNumbers (uses compareTo(gishur.core.math.MathNumber)).
Returns:
Minimum of n1,n2
Throws:
MathNumberException - if the types of n1 and n2 are not comparable.

max

public static MathNumber max(MathNumber n1,
                             MathNumber n2)
Returns the Maximum of the both MathNumbers (uses compareTo(gishur.core.math.MathNumber)).
Returns:
Maximum of n1,n2
Throws:
MathNumberException - if the types of n1 and n2 are not comparable.

sign

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

abs

public abstract MathNumber abs()
Computes |this|.
Returns:
the absolute of this.

negate

public abstract MathNumber negate()
Computes -this.
Returns:
the negative of this.

invert

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

add

public abstract MathNumber add(MathNumber n)
Computes this+n.
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 abstract MathNumber subtract(MathNumber n)
Computes this-n.
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 abstract MathNumber multiply(MathNumber n)
Computes this*n.
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 abstract MathNumber divide(MathNumber n)
Computes this/n.
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.
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.
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.
Returns:
square root of this.
Throws:
java.lang.IllegalArgumentException - if the argument is less than 0.
MathNumberException - if this Method is not supported

byteValue

public byte byteValue()
Returns the value of the number as a byte.
Overrides:
byteValue in class java.lang.Number
Returns:
number as byte

doubleValue

public abstract double doubleValue()
Returns the value of the number as a double.
Overrides:
doubleValue in class java.lang.Number
Returns:
number as double

floatValue

public float floatValue()
Returns the value of the number as a float.
Overrides:
floatValue in class java.lang.Number
Returns:
number as float

intValue

public int intValue()
Returns the value of the number as a int.
Overrides:
intValue in class java.lang.Number
Returns:
number as int

longValue

public long longValue()
Returns the value of the number as a long.
Overrides:
longValue in class java.lang.Number
Returns:
number as long

shortValue

public short shortValue()
Returns the value of the number as a short.
Overrides:
shortValue in class java.lang.Number
Returns:
number as short

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object