|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.math.Overflow
public abstract class Overflow
The Overflow class provides a type safe enumeration of strategies for handling numeric overflows for FixPoint data types. Overflows are typically resolved after performing a FixPoint arithmetic operation or transformation.
The active class functionality is provided by the
quantize
method. This method
evaluates an unscaled BigInteger
value and a
Precision constraint and creates a FixPoint object with a new
unscaled value and precision that conforms to the corresponding
overflow strategy. Depending on the overflow strategy used,
the unscaled integer value or the precision may be changed as
part of the overflow process.
The overflow strategies supported are as follows:
quantizeGrow
method
and the Overflow singletons GROW
and GENERAL
.
quantizeMinimize
method and the Overflow singleton MINIMIZE
.
quantizeModulo
method and the Overflow singletons MODULO
and WRAP
.
quantizeSaturate
method and the Overflow singletons SATURATE
and
CLIP
.
quantizeToZero
method and the Overflow singleton TO_ZERO
.
ArithmeticException
is generated.
This rounding mode is supported by the
singleton TRAP
.
A specific strategy may be chosen dynamically by invoking
forName
or getName
with one of the above strategy names. Alternatively a strategy
may be selected by using one of the static singletons.
Division by zero can trigger the use of the plusInfinity or minusInfinity methods, which return null, except in the case of the to_zero and saturate strategies for which infinity is well-defined.
FixPoint
,
Quantization
,
Rounding
,
Serialized Form
Red |
Red (Ed.Willink) |
Nested Class Summary | |
---|---|
static class |
Overflow.Grow
The grow overflow strategy. |
static class |
Overflow.Minimize
The minimize overflow strategy. |
static class |
Overflow.Modulo
The modulo overflow strategy. |
static class |
Overflow.Saturate
The saturate overflows strategy. |
static class |
Overflow.ToZero
The overflow to zero strategy. |
static class |
Overflow.Trap
The trap overflows strategy. |
Field Summary | |
---|---|
private java.lang.String |
_name
|
private static java.util.Map |
_nameToOverflow
|
static Overflow.Saturate |
CLIP
Singleton implementing Saturate overflow strategy. |
static Overflow.Grow |
GENERAL
Singleton implementing Grow overflow strategy. |
static Overflow.Grow |
GROW
Singleton implementing Grow overflow strategy. |
static Overflow.Minimize |
MINIMIZE
Singleton implementing Minimize overflow strategy. |
static Overflow.Modulo |
MODULO
Singleton implementing Modulo overflow strategy. |
static Overflow.Saturate |
SATURATE
Singleton implementing Saturate overflow strategy. |
static Overflow.Trap |
THROW
Singleton implementing Trap overflow strategy. |
static Overflow.ToZero |
TO_ZERO
Singleton implementing to zero overflow strategy. |
static Overflow.Trap |
TRAP
Singleton implementing Trap overflow strategy. |
static Overflow.Modulo |
WRAP
Singleton implementing Modulo overflow strategy. |
Constructor Summary | |
---|---|
protected |
Overflow(java.lang.String name)
Construct an Overflow object with the given String name. |
Method Summary | |
---|---|
(package private) static void |
_addOverflow(Overflow type,
java.lang.String name)
|
java.lang.Object |
clone()
Return this, that is, return the reference to this object. |
boolean |
equals(java.lang.Object object)
Determine if the argument represents the same Overflow as this object. |
static Overflow |
forName(java.lang.String name)
Return an instance of this class with the specified name. |
static Overflow |
getName(java.lang.String name)
Return an instance of this class with the specified name, or null if none exists. |
int |
hashCode()
Return a hash code value for this object. |
static boolean |
isOutOfRange(java.math.BigInteger bigInt,
Precision precision)
Determines whether the given BigInteger unscaled value is considered an "underflow" or an "overflow" under the given Precision constraint. |
static boolean |
isOverflow(java.math.BigInteger value,
Precision precision)
Determines whether the given BigInteger unscaled value is considered an "overflow" under the given Precision constraint. |
static boolean |
isUnderflow(java.math.BigInteger bigInt,
Precision precision)
Determines whether the given BigInteger unscaled value is considered an "underflow" under the given Precision constraint. |
java.math.BigInteger |
minusInfinity(Quantization quant)
Return the value of minus infinity, or null if unrepresentable. |
static java.util.Iterator |
nameIterator()
Return an iterator for the names of all overflow types. |
java.math.BigInteger |
plusInfinity(Quantization quant)
Return the value of plus infinity, or null if unrepresentable. |
abstract FixPoint |
quantize(java.math.BigInteger integerValue,
Precision precision)
Return a new FixPoint object based on the given BigInteger value and Precision constraint. |
static FixPoint |
quantizeGrow(java.math.BigInteger integerValue,
Precision precision)
Quantize a FixPoint value using a "grow" overflow strategy. |
static FixPoint |
quantizeMinimum(java.math.BigInteger bigInt,
Precision p)
Generates a new FixPoint data value based on the unscaled value bigInt using as few bits as possible. |
static FixPoint |
quantizeModulo(java.math.BigInteger integerValue,
Precision precision)
Quantize a FixPoint value using a "modulo" overflow strategy. |
static FixPoint |
quantizeSaturate(java.math.BigInteger integerValue,
Precision precision)
Quantize a FixPoint value using a "saturate" overflow strategy. |
static FixPoint |
quantizeToZero(java.math.BigInteger integerValue,
Precision precision)
Quantize a FixPoint value using a "to Zero" overflow strategy. |
java.lang.String |
toString()
Return the string representation of this overflow. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Overflow.Grow GROW
public static final Overflow.Modulo MODULO
public static final Overflow.Minimize MINIMIZE
public static final Overflow.Trap TRAP
public static final Overflow.Saturate SATURATE
public static final Overflow.ToZero TO_ZERO
public static final Overflow.Saturate CLIP
public static final Overflow.Grow GENERAL
public static final Overflow.Modulo WRAP
public static final Overflow.Trap THROW
private java.lang.String _name
private static java.util.Map _nameToOverflow
Constructor Detail |
---|
protected Overflow(java.lang.String name)
name
- The String name to give this Overflow strategy.Method Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- Another object.
public static Overflow forName(java.lang.String name)
name
- The name of the Overflow strategy to find.
public static Overflow getName(java.lang.String name) throws java.lang.IllegalArgumentException
name
- The name of the Overflow strategy to find.
java.lang.IllegalArgumentException
- If the string does not
match one of the known strategies.public int hashCode()
hashCode
in class java.lang.Object
public static boolean isOutOfRange(java.math.BigInteger bigInt, Precision precision)
bigInt
- The value to test for underflow.precision
- The Precision constraint to use for the test.
public static boolean isOverflow(java.math.BigInteger value, Precision precision)
value
- The value to test for overflow.precision
- The Precision constraint to use for the test.
public static boolean isUnderflow(java.math.BigInteger bigInt, Precision precision)
bigInt
- The value to test for underflow.precision
- The Precision constraint to use for the test.
public static java.util.Iterator nameIterator()
public java.math.BigInteger minusInfinity(Quantization quant)
The saturation value is returned for the saturate and to_zero strategies for which infinity is quantizable. Null is returned for other strategies.
quant
- The quantization specification.
public java.math.BigInteger plusInfinity(Quantization quant)
The saturation value is returned for the saturate and to_zero strategies for which infinity is quantizable. Null is returned for other strategies.
quant
- The quantization specification.
public abstract FixPoint quantize(java.math.BigInteger integerValue, Precision precision)
integerValue
- The unbounded integer value.precision
- The Precision constraint of the quantization.
public static FixPoint quantizeGrow(java.math.BigInteger integerValue, Precision precision)
integerValue
- unscaled integer value to check for overflowprecision
- the precision constraint used for the overflow check
public static FixPoint quantizeMinimum(java.math.BigInteger bigInt, Precision p)
bigInt
- Unscaled value to use for the FixPoint resultp
- Used to obtain the sign and exponent of the new FixPoint value.
public static FixPoint quantizeModulo(java.math.BigInteger integerValue, Precision precision)
integerValue
- unscaled integer value to check for overflowprecision
- the precision constraint used for the overflow check
public static FixPoint quantizeSaturate(java.math.BigInteger integerValue, Precision precision)
integerValue
- unscaled integer value to check for overflowprecision
- the precision constraint used for the overflow check
public static FixPoint quantizeToZero(java.math.BigInteger integerValue, Precision precision)
integerValue
- unscaled integer value to check for overflowprecision
- the precision constraint used for the overflow check
public java.lang.String toString()
toString
in class java.lang.Object
static void _addOverflow(Overflow type, java.lang.String name)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |