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 FixTypeBOTTOMThe 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.Typeadd(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.Objectclone()Return this, that is, return the reference to this object.Tokenconvert(Token token)Convert the specified token to a token having the type represented by this object.Typedivide(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.booleanequals(java.lang.Object object)Determine if the argument represents the same FixType as this object.PrecisiongetPrecision()Return the precision associated with this FixType.java.lang.ClassgetTokenClass()Return the class for tokens that this type represents.inthashCode()Return a hash code value for this object.voidinitialize(Type type)Set the elements that have declared type BaseType.UNKNOWN to the specified type.booleanisAbstract()Return true if this type does not correspond to a single token class.booleanisCompatible(Type type)Test if the argument type is compatible with this type.booleanisConstant()Test if this Type is a constant.booleanisInstantiable()Test if this type corresponds to an instantiable token classes.booleanisSubstitutionInstance(Type type)Test if the argument is a substitution instance of this type.Typemodulo(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.Typemultiply(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.Typeone()Return the type of the multiplicative identity for elements of this type.Typesubtract(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.StringtoString()Return the string representation of this type.voidupdateType(StructuredType newType)Update this StructuredType to the specified Structured Type.Typezero()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:
addin interfaceType- Overrides:
addin 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:
clonein interfaceType- Specified by:
clonein 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:
convertin 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:
dividein interfaceType- Overrides:
dividein 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:
getTokenClassin interfaceType- Returns:
- The class representing ptolemy.data.token.FixToken.
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCodein 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:
initializein 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:
isAbstractin interfaceType- Overrides:
isAbstractin 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:
isCompatiblein 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:
isConstantin interfaceType- Returns:
- False.
-
isInstantiable
public boolean isInstantiable()
Test if this type corresponds to an instantiable token classes.- Specified by:
isInstantiablein 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:
isSubstitutionInstancein 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:
moduloin interfaceType- Overrides:
moduloin 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:
multiplyin interfaceType- Overrides:
multiplyin 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:
onein interfaceType- Overrides:
onein 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:
subtractin interfaceType- Overrides:
subtractin 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:
updateTypein 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:
zeroin interfaceType- Overrides:
zeroin 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:
_comparein 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:
_getRepresentativein 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:
_greatestLowerBoundin 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:
_leastUpperBoundin 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.
-
-