Package ptolemy.math

Class 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.
    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$
    Author:
    Ed Willink
    See Also:
    FixPoint, Precision, Overflow, Rounding
    Pt.AcceptedRating:
    Red
    Pt.ProposedRating:
    Red (Ed.Willink)
    • 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.
      • 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.