org.znerd.math
Class Product

java.lang.Object
  extended by java.lang.Number
      extended by org.znerd.math.RealNumber
          extended by org.znerd.math.CompositeNumber
              extended by org.znerd.math.AbstractCompositeNumber
                  extended by org.znerd.math.Product
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, RoundingModes

public class Product
extends AbstractCompositeNumber

A product of two real numbers.

Version:
$Revision: 1.5 $ $Date: 2002/08/16 21:35:50 $
Author:
Ernst de Haan (znerd@FreeBSD.org)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.znerd.math.RealNumber
MAXIMUM_RADIX
 
Fields inherited from interface org.znerd.math.RoundingModes
ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP
 
Constructor Summary
protected Product(RealNumber a, RealNumber b)
          Constructs a Product based on the 2 specified operands.
 
Method Summary
static Product createInstance(RealNumber a, RealNumber b)
          Returns a Product with the specified operands.
protected static int determineSign(RealNumber a, RealNumber b)
          Computes the sign of a product with the specified operands.
 java.math.BigDecimal toBigDecimal(int precision, int roundingMode)
          Converts the value of this number to a BigDecimal with the specified precision and rounding mode.
 IntegerNumber trunc()
          Rounds to an integer number towards 0.
 
Methods inherited from class org.znerd.math.AbstractCompositeNumber
getElement, getElementCount, getElements
 
Methods inherited from class org.znerd.math.RealNumber
abs, add, byteValue, compareTo, compareTo, compareToImpl, divide, doubleValue, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, invert, longValue, multiply, negate, pow, powImpl, round, shortValue, subtract, toBigDecimal, toBigInteger, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Product

protected Product(RealNumber a,
                  RealNumber b)
           throws java.lang.IllegalArgumentException
Constructs a Product based on the 2 specified operands.

Parameters:
a - the first operand for the product, not null.
b - the second operand for the product, not null.
Throws:
java.lang.IllegalArgumentException - if a == null || b == null.
Method Detail

createInstance

public static Product createInstance(RealNumber a,
                                     RealNumber b)
                              throws java.lang.IllegalArgumentException
Returns a Product with the specified operands.

Parameters:
a - the first operand, not null.
b - the second operand, not null.
Returns:
the Product instance, possibly newly constructed, never null.
Throws:
java.lang.IllegalArgumentException - if a == null || b == null.

determineSign

protected static int determineSign(RealNumber a,
                                   RealNumber b)
                            throws java.lang.IllegalArgumentException
Computes the sign of a product with the specified operands.

Parameters:
a - the first operand, not null.
b - the second operand, not null.
Returns:
the sign for the product of a and b.
Throws:
java.lang.IllegalArgumentException - if a == null || b == null.

toBigDecimal

public java.math.BigDecimal toBigDecimal(int precision,
                                         int roundingMode)
                                  throws java.lang.IllegalArgumentException
Converts the value of this number to a BigDecimal with the specified precision and rounding mode.

Specified by:
toBigDecimal in class RealNumber
Parameters:
precision - the number of digits behind the decimal point, >= 0.
roundingMode - the rounding mode to use, one of the modes defined in class BigDecimal.
Returns:
a BigDecimal with the rounded value of this number, never null.
Throws:
java.lang.IllegalArgumentException - if precision < 0 or if the rounding mode is not one of the valid rounding modes defined in BigDecimal.

trunc

public IntegerNumber trunc()
Rounds to an integer number towards 0.

Overrides:
trunc in class RealNumber
Returns:
this number truncated to an integer, not null.


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