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

Interface nl.coffee.math.NumberFactory

Implementing Classes:
DefaultNumberFactory

public abstract interface NumberFactory
Interface for a factory that produces RealNumber objects.

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

Method Summary
RealNumber add(RealNumber a, RealNumber b)
          Computes the sum of the arguments.
RationalNumber createFraction(long numerator, long denominator)
          Returns a fraction with the given numerator and denominator, both being a long.
RationalNumber createFraction(IntegerNumber numerator, IntegerNumber denominator)
          Returns a fraction with the given numerator and denominator.
IntegerNumber createInteger(byte[] bytes)
          Returns an integer number from a byte array in two's complement notation.
IntegerNumber createRandomInteger(int maxBytes)
          Returns a pseudo-random IntegerNumber of at maximum maxBytes bytes.
RealNumber multiply(RealNumber a, RealNumber b)
          Computes the product of the arguments.
RealNumber pow(RealNumber base, RealNumber exponent)
          Computes the power for the given base and exponent.
RationalNumber valueOf(double n)
          Returns a rational number from the given double.
IntegerNumber valueOf(long n)
          Returns a rational number from the given long.
IntegerNumber valueOf(java.math.BigInteger n)
          Converts a java.math.
RationalNumber valueOf(java.math.BigDecimal n)
          Converts a java.math.
RealNumber valueOf(java.lang.String s)
          Converts a String to a RealNumber.
 

Method Detail

add

public 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 one of the following applies:
  1. a == null
  2. b == null

multiply

public 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 one of the following applies:
  1. a == null
  2. b == null

pow

public RealNumber pow(RealNumber base,
                      RealNumber exponent)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.ArithmeticException
Computes the 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 one of the following applies:
  1. base == null
  2. exponent == null
java.lang.ArithmeticException - if the power cannot be computed.

createFraction

public 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 RationalNumber createFraction(IntegerNumber numerator,
                                     IntegerNumber denominator)
                                            throws java.lang.IllegalArgumentException,
                                                   java.lang.ArithmeticException
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.IllegalArgumentException - if one of the following applies:
  1. numerator == null
  2. denominator == null
java.lang.ArithmeticException - if the value of denominator is zero.

createInteger

public 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 one of the following applies:
  1. bytes is null
  2. the size of bytes is 0.

valueOf

public 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 any of the following applies:
  1. n represents Infinity
  2. n represents -Infinity
  3. n represents NaN

valueOf

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

valueOf

public 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 n == null.

valueOf

public RationalNumber valueOf(java.math.BigDecimal n)
                                     throws java.lang.IllegalArgumentException
Converts a java.math.BigDecimal to a RationalNumber.
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.

valueOf

public RealNumber valueOf(java.lang.String s)
                                 throws java.lang.IllegalArgumentException,
                                        java.lang.NumberFormatException
Converts a String to a RealNumber.
Parameters:
s - the string to parse.
Returns:
the constructed RealNumber, on success.
Throws:
java.lang.NumberFormatException - if s cannot be parsed.

createRandomInteger

public IntegerNumber createRandomInteger(int maxBytes)
                                                throws java.lang.IllegalArgumentException
Returns a pseudo-random IntegerNumber of at maximum maxBytes bytes. The returned integer number will have a value between -2maxBytes*8 and (2maxBytes-1).
Returns:
the pseudo-random integer.
Throws:
java.lang.IllegalArgumentException - if maxBytes < 1.

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