org.znerd.math
Class NumberCentral

java.lang.Object
  |
  +--org.znerd.math.NumberCentral

public final class NumberCentral
extends Object

A static factory that produces RealNumber objects.

Version:
$Revision: 1.16 $ $Date: 2002/08/19 19:17:05 $
Author:
Ernst de Haan (znerd@FreeBSD.org)

Method Summary
static void checkDivideByZero(RealNumber n)
          Checks if dividing by the specified number would result in a division by zero.
static RationalNumber createFraction(IntegerNumber numerator, IntegerNumber denominator)
          Returns a fraction with the given numerator and denominator.
static RationalNumber createFraction(int numerator, int denominator)
          Returns a fraction with the given numerator and denominator, both being an int.
static IntegerNumber createInteger(byte[] bytes)
          Returns an integer number from a byte array in two's complement notation.
static IntegerNumber createRandomInteger(int numBytes)
          Returns an IntegerNumber with a random value.
static String getVersion()
          Returns the current version of JUMP.
static RealNumber pow(RealNumber base, RealNumber exponent)
          Computes the power of the given base and exponent.
static RationalNumber valueOf(BigDecimal n)
          Converts a BigDecimal to a RationalNumber.
static IntegerNumber valueOf(BigInteger n)
          Converts a BigInteger to an IntegerNumber.
static IntegerNumber valueOf(byte n)
          Converts a byte to an IntegerNumber.
static RationalNumber valueOf(double n)
          Converts a double to a RationalNumber.
static RationalNumber valueOf(float n)
          Converts a float to a RationalNumber.
static IntegerNumber valueOf(int n)
          Converts an int to an IntegerNumber.
static IntegerNumber valueOf(long n)
          Converts a long to an IntegerNumber.
static IntegerNumber valueOf(short n)
          Converts a short to an IntegerNumber.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getVersion

public static String getVersion()
Returns the current version of JUMP.
Returns:
the version of JUMP, for example "0.5-dev", never null.

pow

public static RealNumber pow(RealNumber base,
                             RealNumber exponent)
                      throws IllegalArgumentException,
                             ArithmeticException
Computes the power of the given base and exponent.
Parameters:
base - the base for the power, not null.
exponent - the exponent for the power, not null.
Returns:
the result of baseexponent, never null.
Throws:
IllegalArgumentException - if base == null || exponent == null.
ArithmeticException - if the power cannot be computed.

createFraction

public static RationalNumber createFraction(int numerator,
                                            int denominator)
                                     throws ArithmeticException
Returns a fraction with the given numerator and denominator, both being an int.
Parameters:
numerator - the numerator for the fraction.
denominator - the denominator for the fraction, not 0.
Returns:
the rational number, never null.
Throws:
ArithmeticException - if denominator == 0.

createFraction

public static RationalNumber createFraction(IntegerNumber numerator,
                                            IntegerNumber denominator)
                                     throws ArithmeticException,
                                            IllegalArgumentException
Returns a fraction with the given numerator and denominator.
Parameters:
numerator - the numerator for the fraction, not null.
denominator - the denominator for the fraction, not null.
Returns:
the fraction, never null.
Throws:
IllegalArgumentException - if numerator == null || denominator == null.
ArithmeticException - if the denominator is zero, i.e. denominator.equals(SmallIntegerNumber.ZERO).

createInteger

public static IntegerNumber createInteger(byte[] bytes)
                                   throws IllegalArgumentException
Returns an integer number from a byte array in two's complement notation.
Parameters:
bytes - the two's complement byte array, not null.
Returns:
an integer number that has the same value as represented by the argument, never null.
Throws:
IllegalArgumentException - if bytes == null.

valueOf

public static RationalNumber valueOf(double n)
                              throws IllegalArgumentException
Converts a double to a RationalNumber.
Parameters:
n - the value to be converted, not an infinite number, nor NaN.
Returns:
the result of the conversion, never null.
Throws:
IllegalArgumentException - if Double.isInfinite(n) || Double.isNaN(n)

valueOf

public static RationalNumber valueOf(float n)
                              throws IllegalArgumentException
Converts a float to a RationalNumber.
Parameters:
n - the value to be converted.
Returns:
the result of the conversion, never null.
Throws:
IllegalArgumentException - if Float.isInfinite(n) || Float.isNaN(n)

valueOf

public static IntegerNumber valueOf(long n)
Converts a long to an IntegerNumber.
Parameters:
n - the value to be converted.
Returns:
the result of the conversion, never null.

valueOf

public static IntegerNumber valueOf(int n)
Converts an int to an IntegerNumber.
Parameters:
n - the value to be converted.
Returns:
the result of the conversion, never null.

valueOf

public static IntegerNumber valueOf(short n)
Converts a short to an IntegerNumber.
Parameters:
n - the value to be converted.
Returns:
the result of the conversion, never null.

valueOf

public static IntegerNumber valueOf(byte n)
Converts a byte to an IntegerNumber.
Parameters:
n - the value to be converted.
Returns:
the result of the conversion, never null.

valueOf

public static IntegerNumber valueOf(BigInteger n)
                             throws IllegalArgumentException
Converts a BigInteger to an IntegerNumber.
Parameters:
n - the value to be converted, not null.
Returns:
the result of the conversion, never null.
Throws:
IllegalArgumentException - if n == null.

valueOf

public static RationalNumber valueOf(BigDecimal n)
                              throws IllegalArgumentException
Converts a BigDecimal to a RationalNumber.
Parameters:
n - the value to be converted, not null.
Returns:
the result of the conversion, never null.
Throws:
IllegalArgumentException - if n == null.

createRandomInteger

public static IntegerNumber createRandomInteger(int numBytes)
                                         throws IllegalArgumentException
Returns an IntegerNumber with a random value. The maximum number of bytes for the integer number must be specified.
Parameters:
numBytes - the maximum number of bytes for the constructed number, at least 1.
Returns:
a random integer, never null.
Throws:
IllegalArgumentException - if numBytes < 1.

checkDivideByZero

public static void checkDivideByZero(RealNumber n)
                              throws IllegalArgumentException,
                                     ArithmeticException
Checks if dividing by the specified number would result in a division by zero. If the argument indeed represents zero, then an ArithmeticException is thrown.
Parameters:
n - the number to compare with zero, not null.
Throws:
IllegalArgumentException - if n == null.
ArithmeticException - if n.getSign() == 0.


See http://jump-math.sourceforge.net/.