Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class nl.coffee.math.NumberCentral

java.lang.Object
  |
  +--nl.coffee.math.NumberCentral

public final class NumberCentral
extends java.lang.Object
A static factory that produces RealNumber objects.

Since:
JUMP_1.0
Version:
1.0 199809.24
Author:
Ernst de Haan

Method Summary
static RealNumber add(RealNumber a, RealNumber b)
          Computes the sum of the arguments.
static RationalNumber createFraction(long numerator, long denominator)
          Returns a fraction with the given numerator and denominator, both being a long.
static RationalNumber createFraction(IntegerNumber numerator, IntegerNumber denominator)
          Returns a fraction with the given numerator and denominator.
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 NumberFactory getDefaultFactory()
          Retrieves the default NumberFactory.
static RealNumber multiply(RealNumber a, RealNumber b)
          Computes the product of the arguments.
static RealNumber pow(RealNumber base, RealNumber exponent)
          Computes the a power for the given base and exponent.
static void setDefaultFactory(NumberFactory newDefault)
          Sets the default NumberFactory.
static RationalNumber valueOf(double n)
          Returns a rational number from the given double.
static IntegerNumber valueOf(long n)
          Returns a rational number from the given long.
static IntegerNumber valueOf(java.math.BigInteger n)
          Converts a java.math.
static RationalNumber valueOf(java.math.BigDecimal n)
          Converts a java.math.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Method Detail

getDefaultFactory

public static final NumberFactory getDefaultFactory()
Retrieves the default NumberFactory. This method will never return null.
Returns:
the NumberFactory that is set as the default.

setDefaultFactory

public static final void setDefaultFactory(NumberFactory newDefault)
Sets the default NumberFactory.

The default NumberFactory will be set to the fallback default if the argument is null.

Parameters:
factory - the new default factory, or null if the default factory should be set to the fallback default.

add

public static RealNumber add(RealNumber a,
                             RealNumber b)
                                    throws java.lang.IllegalArgumentException
Computes the sum of the arguments.
Parameters:
a - the first operand
b - the second operand
Returns:
the sum of a and b.
Throws:
java.lang.IllegalArgumentException - if either argument is null.

multiply

public static RealNumber multiply(RealNumber a,
                                  RealNumber b)
                                         throws java.lang.IllegalArgumentException
Computes the product of the arguments.
Parameters:
a - the first operand
b - the second operand
Returns:
the product of a and b.
Throws:
java.lang.IllegalArgumentException - if either argument is null.

pow

public static RealNumber pow(RealNumber base,
                             RealNumber exponent)
                                    throws java.lang.IllegalArgumentException,
                                           java.lang.ArithmeticException
Computes the a power for the given base and exponent.
Parameters:
base - the base for the power.
exponent - the exponent for the power.
Returns:
baseexponent
Throws:
java.lang.IllegalArgumentException - if either argument is null.
java.lang.ArithmeticException - if the power cannot be computed.

createFraction

public static RationalNumber createFraction(long numerator,
                                            long denominator)
                                                   throws java.lang.ArithmeticException
Returns a fraction with the given numerator and denominator, both being a long.
Parameters:
numerator - the numerator for the fraction.
denominator - the denominator for the fraction.
Returns:
the (possibly newly constructed) fraction.
Throws:
java.lang.ArithmeticException - if the value of denominator is zero.

createFraction

public static RationalNumber createFraction(IntegerNumber numerator,
                                            IntegerNumber denominator)
                                                   throws java.lang.ArithmeticException,
                                                          java.lang.IllegalArgumentException
Returns a fraction with the given numerator and denominator.
Parameters:
numerator - the numerator for the fraction.
denominator - the denominator for the fraction.
Returns:
the (possibly newly constructed) fraction.
Throws:
java.lang.ArithmeticException - if the value of denominator is zero.
java.lang.IllegalArgumentException - if either one or both of the arguments are null.

createInteger

public static IntegerNumber createInteger(byte[] bytes)
                                                 throws java.lang.IllegalArgumentException
Returns an integer number from a byte array in two's complement notation.
Parameters:
bytes - the two's complement byte array.
Returns:
the (possibly newly constructed) integer number.
Throws:
java.lang.IllegalArgumentException - if the argument is null or the array has length 0.

valueOf

public static RationalNumber valueOf(double n)
                                            throws java.lang.IllegalArgumentException
Returns a rational number from the given double.
Parameters:
n - the original value.
Returns:
the converted RealNumber.
Throws:
java.lang.IllegalArgumentException - if the object represents Infinity, -Infinity or NaN.

valueOf

public static IntegerNumber valueOf(long n)
Returns a rational number from the given long.
Parameters:
n - the original value.
Returns:
the converted RealNumber.

valueOf

public static IntegerNumber valueOf(java.math.BigInteger n)
                                           throws java.lang.IllegalArgumentException
Converts a java.math.BigInteger to an IntegerNumber.
Parameters:
n - the BigInteger to convert.
Returns:
the (possibly newly constructed) integer number with the value of n.
Throws:
java.lang.IllegalArgumentException - if the argument is null.

valueOf

public static RationalNumber valueOf(java.math.BigDecimal n)
                                            throws java.lang.IllegalArgumentException
Converts a java.math.BigDecimal to an IntegerNumber.
Parameters:
n - the BigDecimal to convert.
Returns:
the (possibly newly constructed) rational number with the value of n.
Throws:
java.lang.IllegalArgumentException - if the argument is null.

createRandomInteger

public static IntegerNumber createRandomInteger(int numBytes)
Returns an IntegerNumber with a random value.
Parameters:
the - maximum number of bytes for the constructed number.
Returns:
a random integer.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD