ptolemy.math
Class FixPointQuantization

java.lang.Object
  extended by ptolemy.math.Quantization
      extended by ptolemy.math.FixPointQuantization
All Implemented Interfaces:
java.io.Serializable, 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

The active class functionality is provided by the quantize method, which is normally invoked from FixPoint.quantize to enforce quantization constraints upon the result of an unconstrained computation.

An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified.

Since:
Ptolemy II 2.1
Version:
$Id: FixPointQuantization.java 47513 2007-12-07 06:32:21Z cxh $
Author:
Ed Willink
See Also:
FixPoint, Precision, Overflow, Rounding, Serialized Form
Accepted Rating:
Red
Proposed Rating:
Red (Ed.Willink)

Field Summary
protected  Precision _precision
          The precision.
 
Fields inherited from class ptolemy.math.Quantization
_overflow, _rounding
 
Constructor Summary
FixPointQuantization(Precision precision, Overflow overflow, Rounding rounding)
          Construct a FixPointQuantization with specified precision, overflow and rounding.
FixPointQuantization(java.lang.String string)
          Construct a FixPointQuantization object based on the provided string.
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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.

FixPointQuantization

public FixPointQuantization(Precision precision,
                            Overflow overflow,
                            Rounding rounding)
Construct a FixPointQuantization with specified precision, overflow and rounding.

Parameters:
precision - The precision.
overflow - The overflow.
rounding - The rounding.
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 class Quantization
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 class Quantization
Returns:
The precision.

getPrecision

public Precision getPrecision()
Return the precision.

Specified by:
getPrecision in class Quantization
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 class Quantization
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 class Quantization
Returns:
A string representing this quantization.