org.znerd.math
Class Power
java.lang.Object
|
+--java.lang.Number
|
+--org.znerd.math.RealNumber
|
+--org.znerd.math.CompositeNumber
|
+--org.znerd.math.AbstractCompositeNumber
|
+--org.znerd.math.Power
- public class Power
- extends AbstractCompositeNumber
A power, consisting of a base and an exponent.
- Version:
- $Revision: 1.2 $ $Date: 2002/06/12 21:05:40 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
- See Also:
- Serialized Form
Constructor Summary |
protected |
Power(RealNumber base,
RealNumber exponent)
Constructs a Power with the specified base and exponent. |
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,
shortValue,
subtract,
toBigDecimal,
toBigInteger,
toString |
Power
protected Power(RealNumber base,
RealNumber exponent)
throws IllegalArgumentException
- Constructs a
Power
with the specified base and exponent.
- Parameters:
base
- the base for the power, not null
.exponent
- the exponent for the power, not null
.- Throws:
- IllegalArgumentException - if
base == null || exponent == null
.
createInstance
public static Power createInstance(RealNumber a,
RealNumber b)
throws IllegalArgumentException
- Returns a
Power
with the specified operands.
- Parameters:
base
- the base for the power, not null
.exponent
- the exponent for the power, not null
.- Returns:
- the
Power
instance, possibly newly constructed. - Throws:
- IllegalArgumentException - if
base == null || exponent == null
.
determineSign
protected static int determineSign(RealNumber base,
RealNumber exponent)
throws IllegalArgumentException
- Computes the sign of a power with the specified operands.
- Parameters:
base
- the base for the power, not null
.exponent
- the exponent for the power, not null
.- Returns:
- the
Power
instance, possibly newly constructed. - Throws:
- IllegalArgumentException - if
base == null || exponent == null
.
getBase
public RealNumber getBase()
- Returns the base of this power.
- Returns:
- the base, never
null
.
getExponent
public RealNumber getExponent()
- Returns the exponent of this power.
- Returns:
- the exponent, never
null
.
toBigDecimal
public BigDecimal toBigDecimal(int precision,
int roundingMode)
throws IllegalArgumentException
- Description copied from class: RealNumber
- Converts the value of this number to a
BigDecimal
with the
specified precision and rounding mode.
- Overrides:
- toBigDecimal in class RealNumber
- Tags copied from 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, never
null
. - Throws:
- IllegalArgumentException - if one of the following applies:
- precision < 0
- roundingMode is not one of the valid rounding modes
defined in class
BigDecimal
trunc
public IntegerNumber trunc()
- Description copied from class: RealNumber
- Rounds to an integer number towards 0.
- Overrides:
- trunc in class RealNumber
- Tags copied from class: RealNumber
- Returns:
- this real number truncated to an integer, never
null
.
See http://jump-math.sourceforge.net/.