Package ptolemy.data.type
Class FixType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- ptolemy.data.type.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)
-
-
Field Summary
Fields Modifier and Type Field Description static FixType
BOTTOM
The bottom fix type.-
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
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 ptolemy.data.type.StructuredType
depth, getTypeHash
-
-
-
-
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 interfaceType
- Overrides:
add
in classStructuredType
- 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 interfaceType
- Specified by:
clone
in classStructuredType
- Returns:
- A FixType.
-
convert
public Token convert(Token token) throws IllegalActionException
Convert the specified token to a token having the type represented by this object.- Specified by:
convert
in interfaceType
- Parameters:
token
- A token.- Returns:
- A token.
- Throws:
IllegalActionException
- If lossless conversion cannot be done.
-
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 interfaceType
- Overrides:
divide
in classStructuredType
- 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.
-
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 interfaceType
- Returns:
- The class representing ptolemy.data.token.FixToken.
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCode
in classjava.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 classStructuredType
- 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 interfaceType
- Overrides:
isAbstract
in classStructuredType
- 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 interfaceType
- 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 interfaceType
- Returns:
- False.
-
isInstantiable
public boolean isInstantiable()
Test if this type corresponds to an instantiable token classes.- Specified by:
isInstantiable
in interfaceType
- 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 interfaceType
- 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 interfaceType
- Overrides:
modulo
in classStructuredType
- 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 interfaceType
- Overrides:
multiply
in classStructuredType
- 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 interfaceType
- Overrides:
one
in classStructuredType
- 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 interfaceType
- Overrides:
subtract
in classStructuredType
- 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.
-
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 classStructuredType
- 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 interfaceType
- Overrides:
zero
in classStructuredType
- 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 classStructuredType
- 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 classStructuredType
- 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 classStructuredType
- 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 classStructuredType
- 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.
-
-