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.DefaultNumberFactory

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

public class DefaultNumberFactory
extends java.lang.Object
implements NumberFactory
Default implementation of a NumberFactory.

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

Field Summary
java.util.Random randomGenerator
          The Random object used to obtain pseudo-random numbers.
static DefaultNumberFactory SHARED_INSTANCE
          The shared instance of this class.
 
Constructor Summary
DefaultNumberFactory()
          Constructs a new DefaultNumberFactory.
 
Method Summary
RealNumber add(RealNumber a, RealNumber b)
           
RationalNumber createFraction(long numerator, long denominator)
           
RationalNumber createFraction(IntegerNumber numerator, IntegerNumber denominator)
           
IntegerNumber createInteger(byte[] bytes)
           
IntegerNumber createRandomInteger(int maxBytes)
           
RealNumber multiply(RealNumber a, RealNumber b)
           
RealNumber pow(RealNumber base, RealNumber exponent)
           
RationalNumber valueOf(double n)
           
IntegerNumber valueOf(long n)
           
IntegerNumber valueOf(java.math.BigInteger n)
           
RationalNumber valueOf(java.math.BigDecimal n)
           
RealNumber valueOf(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

SHARED_INSTANCE

public static DefaultNumberFactory SHARED_INSTANCE
The shared instance of this class. The instance can be shared because it has no state.

randomGenerator

protected java.util.Random randomGenerator
The Random object used to obtain pseudo-random numbers.

This field is initialized upon construction.

Constructor Detail

DefaultNumberFactory

protected DefaultNumberFactory()
Constructs a new DefaultNumberFactory.
Method Detail

add

public RealNumber add(RealNumber a,
                      RealNumber b)
                             throws java.lang.IllegalArgumentException
Description copied from interface:
Computes the sum of the arguments.
Specified by:
add in interface NumberFactory

multiply

public RealNumber multiply(RealNumber a,
                           RealNumber b)
                                  throws java.lang.IllegalArgumentException
Description copied from interface:
Computes the product of the arguments.
Specified by:
multiply in interface NumberFactory

pow

public RealNumber pow(RealNumber base,
                      RealNumber exponent)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.ArithmeticException
Description copied from interface:
Computes the power for the given base and exponent.
Specified by:
pow in interface NumberFactory

createFraction

public RationalNumber createFraction(long numerator,
                                     long denominator)
                                            throws java.lang.ArithmeticException
Description copied from interface:
Returns a fraction with the given numerator and denominator, both being a long.
Specified by:
createFraction in interface NumberFactory

createFraction

public RationalNumber createFraction(IntegerNumber numerator,
                                     IntegerNumber denominator)
                                            throws java.lang.IllegalArgumentException,
                                                   java.lang.ArithmeticException
Description copied from interface:
Returns a fraction with the given numerator and denominator.
Specified by:
createFraction in interface NumberFactory

createInteger

public IntegerNumber createInteger(byte[] bytes)
Description copied from interface:
Returns an integer number from a byte array in two's complement notation.
Specified by:
createInteger in interface NumberFactory

valueOf

public RationalNumber valueOf(double n)
                                     throws java.lang.IllegalArgumentException
Description copied from interface:
Returns a rational number from the given double.
Specified by:
valueOf in interface NumberFactory

valueOf

public IntegerNumber valueOf(long n)
Description copied from interface:
Returns a rational number from the given long.
Specified by:
valueOf in interface NumberFactory

valueOf

public IntegerNumber valueOf(java.math.BigInteger n)
                                    throws java.lang.IllegalArgumentException
Description copied from interface:
Converts a java.math.BigInteger to an IntegerNumber.
Specified by:
valueOf in interface NumberFactory

valueOf

public RationalNumber valueOf(java.math.BigDecimal n)
                                     throws java.lang.IllegalArgumentException
Description copied from interface:
Converts a java.math.BigDecimal to a RationalNumber.
Specified by:
valueOf in interface NumberFactory

valueOf

public RealNumber valueOf(java.lang.String s)
                                 throws java.lang.IllegalArgumentException,
                                        java.lang.NumberFormatException
Description copied from interface:
Converts a String to a RealNumber.
Specified by:
valueOf in interface NumberFactory

createRandomInteger

public IntegerNumber createRandomInteger(int maxBytes)
                                                throws java.lang.IllegalArgumentException
Description copied from interface:
Returns a pseudo-random IntegerNumber of at maximum maxBytes bytes. The returned integer number will have a value between -2maxBytes*8 and (2maxBytes-1).
Specified by:
createRandomInteger in interface NumberFactory

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