Package ptolemy.math
Class FixPointQuantization
- java.lang.Object
-
- ptolemy.math.Quantization
-
- ptolemy.math.FixPointQuantization
-
- All Implemented Interfaces:
java.lang.Cloneable
public class FixPointQuantization extends Quantization
The FixPointQuantization class defines the mapping of numeric values with unlimited precision to the finite precision supported by arithmetic using the FixPoint class.It comprises a
- Precision: to define the accuracy of the finite precision numbers.
- Overflow: to define the treatment of out-of-range numbers.
- Rounding: to define the loss of precision for in-range numbers.
An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified.
-
-
Field Summary
Fields Modifier and Type Field Description protected Precision
_precision
The precision.-
Fields inherited from class ptolemy.math.Quantization
_overflow, _rounding
-
-
Constructor Summary
Constructors Constructor Description FixPointQuantization(java.lang.String string)
Construct a FixPointQuantization object based on the provided string.FixPointQuantization(Precision precision, Overflow overflow, Rounding rounding)
Construct a FixPointQuantization with specified precision, overflow and rounding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object object)
Return true if the given object describes the same mapping to quantized values as this object.Precision
getMantissaPrecision()
Return the precision of the mantissa of the value.Precision
getPrecision()
Return the precision.int
hashCode()
Return a hash code value for this FixPointQuantization.FixPointQuantization
setOverflow(Overflow overflow)
Return a FixPointQuantization with a changed overflow strategy.FixPointQuantization
setPrecision(Precision precision)
Return a FixPointQuantization with a changed precision.FixPointQuantization
setRounding(Rounding rounding)
Return a FixPointQuantization with a changed rounding strategy.java.lang.String
toString()
Return a string representing this quantization.-
Methods inherited from class ptolemy.math.Quantization
clone, getEpsilonValue, getExactOverflow, getExactRounding, getExponentBitLength, getFractionBitLength, getIntegerBitLength, getMantissaBitLength, getMaximumUnscaledValue, getMaximumValue, getMinimumUnscaledValue, getMinimumValue, getModuloUnscaledValue, getNumberOfBits, getNumberOfLevels, getOverflow, getRounding, getTinyValue
-
-
-
-
Field Detail
-
_precision
protected Precision _precision
The precision.
-
-
Constructor Detail
-
FixPointQuantization
public FixPointQuantization(java.lang.String string) throws java.lang.IllegalArgumentException
Construct a FixPointQuantization object based on the provided string. The string may consist of just precision or precision, overflow or precision, overflow, rounding, and may optionally be enclosed in parentheses.precision must be one of the Precision formats; integer-bits.fraction-bits or total-bits/integer-bits.
overflow must be one of the Overflow strategies; e.g. saturate or modulo or trap. The default is saturate.
rounding must be one of the Rounding strategies; e.g. up or half_even or unnecessary. The default is nearest.
- Parameters:
string
- The string representing the quantization specification.- Throws:
java.lang.IllegalArgumentException
- If the precision string supplied, overflow strategy or rounding strategy does not match one of the known formats.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object object)
Return true if the given object describes the same mapping to quantized values as this object.- Overrides:
equals
in classQuantization
- Parameters:
object
- The FixPointQuantization object to use for equality checking.- Returns:
- True if the quantizations are equal.
-
getMantissaPrecision
public Precision getMantissaPrecision()
Return the precision of the mantissa of the value.- Specified by:
getMantissaPrecision
in classQuantization
- Returns:
- The precision.
-
getPrecision
public Precision getPrecision()
Return the precision.- Specified by:
getPrecision
in classQuantization
- Returns:
- Precision object.
- See Also:
setPrecision(Precision)
-
hashCode
public int hashCode()
Return a hash code value for this FixPointQuantization. This method returns the bitwise xor of the hashcode of the superclass (Quantization) and the hashcode of the precision.- Overrides:
hashCode
in classQuantization
- Returns:
- A hash code value for this Quantization.
-
setOverflow
public FixPointQuantization setOverflow(Overflow overflow)
Return a FixPointQuantization with a changed overflow strategy.- Parameters:
overflow
- The new overflow strategy.- Returns:
- A new quantization.
-
setPrecision
public FixPointQuantization setPrecision(Precision precision)
Return a FixPointQuantization with a changed precision.- Parameters:
precision
- The new precision.- Returns:
- A new quantization.
- See Also:
getPrecision()
-
setRounding
public FixPointQuantization setRounding(Rounding rounding)
Return a FixPointQuantization with a changed rounding strategy.- Parameters:
rounding
- The new rounding.strategy.- Returns:
- A new quantization.
-
toString
public java.lang.String toString()
Return a string representing this quantization. The string is expressed as "(m.n, o, p)", where m indicates the number of integer bits, n represents the number of fractional bits and o represents the overflow strategy and r represents the rounding strategy.- Specified by:
toString
in classQuantization
- Returns:
- A string representing this quantization.
-
-