Class FixType

  • All Implemented Interfaces:
    java.lang.Cloneable, Type

    public class FixType
    extends StructuredType
    implements java.lang.Cloneable
    This class represents the type of fix point token objects. Generally the type of a fix point token includes the precision of the token, along with the rounding and quantization techniques that are being applied.
    Since:
    Ptolemy II 2.1
    Version:
    $Id$
    Author:
    Steve Neuendorffer
    Pt.AcceptedRating:
    Red
    Pt.ProposedRating:
    Red (neuendor)
    • Constructor Summary

      Constructors 
      Constructor Description
      FixType()
      Construct a new fix type, with no integer bits and no fractional bits.
      FixType​(Precision precision)
      Construct a new fix type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void _checkPrecision()
      Check the precision.
      protected int _compare​(StructuredType type)
      Compare this type with the specified type.
      protected StructuredType _getRepresentative()
      Return a static instance of this structured type.
      protected StructuredType _greatestLowerBound​(StructuredType type)
      Return the greatest lower bound of this type with the specified type.
      protected StructuredType _leastUpperBound​(StructuredType type)
      Return the least upper bound of this type with the specified type.
      Type add​(Type rightArgumentType)
      Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.
      java.lang.Object clone()
      Return this, that is, return the reference to this object.
      Token convert​(Token token)
      Convert the specified token to a token having the type represented by this object.
      Type divide​(Type rightArgumentType)
      Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.
      boolean equals​(java.lang.Object object)
      Determine if the argument represents the same FixType as this object.
      Precision getPrecision()
      Return the precision associated with this FixType.
      java.lang.Class getTokenClass()
      Return the class for tokens that this type represents.
      int hashCode()
      Return a hash code value for this object.
      void initialize​(Type type)
      Set the elements that have declared type BaseType.UNKNOWN to the specified type.
      boolean isAbstract()
      Return true if this type does not correspond to a single token class.
      boolean isCompatible​(Type type)
      Test if the argument type is compatible with this type.
      boolean isConstant()
      Test if this Type is a constant.
      boolean isInstantiable()
      Test if this type corresponds to an instantiable token classes.
      boolean isSubstitutionInstance​(Type type)
      Test if the argument is a substitution instance of this type.
      Type modulo​(Type rightArgumentType)
      Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.
      Type multiply​(Type rightArgumentType)
      Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.
      Type one()
      Return the type of the multiplicative identity for elements of this type.
      Type subtract​(Type rightArgumentType)
      Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.
      java.lang.String toString()
      Return the string representation of this type.
      void updateType​(StructuredType newType)
      Update this StructuredType to the specified Structured Type.
      Type zero()
      Return the type of the additive identity for elements of this type.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • BOTTOM

        public static final FixType BOTTOM
        The bottom fix type.
    • Constructor Detail

      • FixType

        public FixType()
        Construct a new fix type, with no integer bits and no fractional bits. This (rather useless) type represents the bottom of the FixPoint type lattice.
      • FixType

        public FixType​(Precision precision)
        Construct a new fix type.
        Parameters:
        precision - The precision.
    • Method Detail

      • add

        public Type add​(Type rightArgumentType)
        Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.
        Specified by:
        add in interface Type
        Overrides:
        add in class StructuredType
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • clone

        public java.lang.Object clone()
        Return this, that is, return the reference to this object.
        Specified by:
        clone in interface Type
        Specified by:
        clone in class StructuredType
        Returns:
        A FixType.
      • divide

        public Type divide​(Type rightArgumentType)
        Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.
        Specified by:
        divide in interface Type
        Overrides:
        divide in class StructuredType
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • equals

        public boolean equals​(java.lang.Object object)
        Determine if the argument represents the same FixType as this object.
        Specified by:
        equals in interface Type
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - A Type.
        Returns:
        Always return true
      • getPrecision

        public Precision getPrecision()
        Return the precision associated with this FixType.
        Returns:
        A Precision.
      • getTokenClass

        public java.lang.Class getTokenClass()
        Return the class for tokens that this type represents.
        Specified by:
        getTokenClass in interface Type
        Returns:
        The class representing ptolemy.data.token.FixToken.
      • hashCode

        public int hashCode()
        Return a hash code value for this object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code for the token class of this type.
      • initialize

        public void initialize​(Type type)
        Set the elements that have declared type BaseType.UNKNOWN to the specified type.
        Specified by:
        initialize in class StructuredType
        Parameters:
        type - A Type.
      • isAbstract

        public boolean isAbstract()
        Return true if this type does not correspond to a single token class. This occurs if the type is not instantiable, or it represents either an abstract base class or an interface. This method should be overridden in derived classes to return true only for types which are not abstract.
        Specified by:
        isAbstract in interface Type
        Overrides:
        isAbstract in class StructuredType
        Returns:
        true.
      • isCompatible

        public boolean isCompatible​(Type type)
        Test if the argument type is compatible with this type. The method returns true if this type is UNKNOWN, since any type is a substitution instance of it. If this type is not UNKNOWN, this method returns true if the argument type is less than or equal to this type in the type lattice, and false otherwise.
        Specified by:
        isCompatible in interface Type
        Parameters:
        type - An instance of Type.
        Returns:
        True if the argument is compatible with this type.
      • isConstant

        public boolean isConstant()
        Test if this Type is a constant. A Type is a constant if it does not contain BaseType.UNKNOWN in any level within it.
        Specified by:
        isConstant in interface Type
        Returns:
        False.
      • isInstantiable

        public boolean isInstantiable()
        Test if this type corresponds to an instantiable token classes.
        Specified by:
        isInstantiable in interface Type
        Returns:
        True if the precision of this fix type has any bits.
      • isSubstitutionInstance

        public boolean isSubstitutionInstance​(Type type)
        Test if the argument is a substitution instance of this type.
        Specified by:
        isSubstitutionInstance in interface Type
        Parameters:
        type - A Type.
        Returns:
        False.
      • modulo

        public Type modulo​(Type rightArgumentType)
        Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.
        Specified by:
        modulo in interface Type
        Overrides:
        modulo in class StructuredType
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • multiply

        public Type multiply​(Type rightArgumentType)
        Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type. The resulting Precision of a multiply between two FixType arguments is as follows: the integer location is the sum of the integer locations of the two arguments and the fractional location is the sum of the fractional locations of the two arguments.
        Specified by:
        multiply in interface Type
        Overrides:
        multiply in class StructuredType
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • one

        public Type one()
        Return the type of the multiplicative identity for elements of this type.
        Specified by:
        one in interface Type
        Overrides:
        one in class StructuredType
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • subtract

        public Type subtract​(Type rightArgumentType)
        Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.
        Specified by:
        subtract in interface Type
        Overrides:
        subtract in class StructuredType
        Parameters:
        rightArgumentType - The type to add to this type.
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • toString

        public java.lang.String toString()
        Return the string representation of this type.
        Specified by:
        toString in interface Type
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String.
      • updateType

        public void updateType​(StructuredType newType)
                        throws IllegalActionException
        Update this StructuredType to the specified Structured Type. The specified type must have the same structure as this type. This method will only update the component type that is BaseType.UNKNOWN, and leave the constant part of this type intact.
        Overrides:
        updateType in class StructuredType
        Parameters:
        newType - A StructuredType.
        Throws:
        IllegalActionException - If the specified type has a different structure.
      • zero

        public Type zero()
        Return the type of the additive identity for elements of this type.
        Specified by:
        zero in interface Type
        Overrides:
        zero in class StructuredType
        Returns:
        A new type, or BaseType.GENERAL, if the operation does not make sense for the given types.
      • _compare

        protected int _compare​(StructuredType type)
        Compare this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating this type is lower than, equal to, higher than, or incomparable with the specified type in the type hierarchy, respectively.
        Specified by:
        _compare in class StructuredType
        Parameters:
        type - a StructuredType.
        Returns:
        An integer.
        Throws:
        java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.
      • _getRepresentative

        protected StructuredType _getRepresentative()
        Return a static instance of this structured type. The return value is used by TypeLattice to represent this type.
        Specified by:
        _getRepresentative in class StructuredType
        Returns:
        a StructuredType.
      • _greatestLowerBound

        protected StructuredType _greatestLowerBound​(StructuredType type)
        Return the greatest lower bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.
        Specified by:
        _greatestLowerBound in class StructuredType
        Parameters:
        type - a StructuredType.
        Returns:
        a StructuredType.
        Throws:
        java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.
      • _leastUpperBound

        protected StructuredType _leastUpperBound​(StructuredType type)
        Return the least upper bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.
        Specified by:
        _leastUpperBound in class StructuredType
        Parameters:
        type - a StructuredType.
        Returns:
        a StructuredType.
        Throws:
        java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.
      • _checkPrecision

        protected void _checkPrecision()
        Check the precision. If the number of bits is greater than 128, throw an exception.