Class BasicRationalNumber
java.lang.Object
java.lang.Number
org.znerd.math.RealNumber
org.znerd.math.RationalNumber
org.znerd.math.BasicRationalNumber
- All Implemented Interfaces:
Serializable, Comparable, RoundingModes
Basic implementation of a rational number.
This implementation simply encapsulates a numerator and
a denominator field. Both are
IntegerNumber
objects.- Version:
- $Revision: 1.8 $ $Date: 2002/08/16 22:07:32 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BasicRationalNumberCached instance that represents the number minus one half, -1/2.static final BasicRationalNumberCached instance that represents the number one half, 1/2.Fields inherited from class RealNumber
MAXIMUM_RADIXFields inherited from interface RoundingModes
ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBasicRationalNumber(IntegerNumber numerator, IntegerNumber denominator) Constructs a newBasicRationalNumberfrom a numerator and a denominator. -
Method Summary
Modifier and TypeMethodDescriptionstatic BasicRationalNumbercreateInstance(IntegerNumber numerator, IntegerNumber denominator) Returns an instance of aBasicRationalNumberwith the given numerator and denominator.Methods inherited from class RationalNumber
add, add, compareTo, compareToImpl, compareToImpl, compareToImpl2, divide, divide, doubleValue, getDenominator, getNumerator, invert, multiply, multiply, negate, pow, powImpl, powImpl, subtract, subtract, toBigDecimal, toBigDecimal, truncMethods inherited from class RealNumber
abs, byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, longValue, pow, round, shortValue, toBigInteger, toString
-
Field Details
-
ONE_HALF
Cached instance that represents the number one half, 1/2. -
MINUS_ONE_HALF
Cached instance that represents the number minus one half, -1/2.
-
-
Constructor Details
-
BasicRationalNumber
protected BasicRationalNumber(IntegerNumber numerator, IntegerNumber denominator) throws IllegalArgumentException, ArithmeticException Constructs a newBasicRationalNumberfrom a numerator and a denominator.- Parameters:
numerator- the numerator for the fraction.denominator- the denominator for the fraction.- Throws:
IllegalArgumentException- if one of the following applies:- numerator ==
null - denominator ==
null
- numerator ==
ArithmeticException- if the value of denominator is zero.
-
-
Method Details
-
createInstance
public static BasicRationalNumber createInstance(IntegerNumber numerator, IntegerNumber denominator) throws IllegalArgumentException, ArithmeticException Returns an instance of aBasicRationalNumberwith the given numerator and denominator.- Parameters:
numerator- the numerator for the fraction.denominator- the denominator for the fraction.- Returns:
- the (possibly newly constructed) instance.
- Throws:
IllegalArgumentException- if one of the following applies:- numerator ==
null - denominator ==
null
- numerator ==
ArithmeticException- if the value ofdenominatoris zero.
-