ptolemy.actor.lib.conversions
Class FixToFix

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Transformer
                              extended byptolemy.actor.lib.conversions.Converter
                                  extended byptolemy.actor.lib.conversions.FixToFix
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor

public class FixToFix
extends Converter

This actor converts a FixToken into another FixToken with a specified precision. Note that this conversion may be lossy, in that the output may be an approximation of the input. The approximation can be constructed using a variety of rounding and overflow strategies,

The precision of the output is given by the precision parameter, which is an integer matrix of the form [m, n], where the total number of bits in the output is m, of which n are integer bits. The default precision is [16, 2], which means that an output has 16 bits, of which 2 bits represent the integer part.

The rounding strategy is defined by the rounding parameter and defaults to nearest (or half_floor), selecting the nearest representable value. The floor value nearer to minus infinity is used for values half way between representable values. Other strategies such as truncate are described under ptolemy.math.Rounding.

The overflow strategy is defined by the overflow parameter and defaults to saturate (or clip). Out of range values are saturated to the nearest representable value. Other strategies such as modulo are described under ptolemy.math.Overflow.

Since:
Ptolemy II 1.0
Version:
$Id: FixToFix.java,v 1.29 2004/04/13 03:05:31 cxh Exp $
Author:
Bart Kienhuis, Edward A. Lee, Ed Willink
See Also:
FixToken, Overflow, Precision, Rounding, Serialized Form
Accepted Rating:
Green (pwhitake)
Proposed Rating:
Green (pwhitake)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.kernel.util.StringAttribute overflow
          The overflow strategy used to convert a double into a fix point, such as "saturate" or "to_zero".
 ptolemy.data.expr.Parameter precision
          The precision of the output fix-point number, represented by an integer matrix.
 ptolemy.kernel.util.StringAttribute rounding
          The rounding strategy used, such as "nearest" or "truncate".
 
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
FixToFix(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.Attribute attribute)
          Override the base class to set locally cached variables.
 void fire()
          Read at most one token from the input and convert it to a fixed-point value with the precision given by the precision parameter, overflow strategy given by the overflow parameter, and rounding strategy given by the rounding parameter.
 boolean prefire()
          Return false if the input port has no token, otherwise return what the superclass returns (presumably true).
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
initialize, iterate, postfire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

precision

public ptolemy.data.expr.Parameter precision
The precision of the output fix-point number, represented by an integer matrix.


rounding

public ptolemy.kernel.util.StringAttribute rounding
The rounding strategy used, such as "nearest" or "truncate".


overflow

public ptolemy.kernel.util.StringAttribute overflow
The overflow strategy used to convert a double into a fix point, such as "saturate" or "to_zero".

Constructor Detail

FixToFix

public FixToFix(ptolemy.kernel.CompositeEntity container,
                java.lang.String name)
         throws ptolemy.kernel.util.NameDuplicationException,
                ptolemy.kernel.util.IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.IllegalActionException
Override the base class to set locally cached variables.

Parameters:
attribute - The attribute that changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the parameter value is invalid.

fire

public void fire()
          throws ptolemy.kernel.util.IllegalActionException
Read at most one token from the input and convert it to a fixed-point value with the precision given by the precision parameter, overflow strategy given by the overflow parameter, and rounding strategy given by the rounding parameter.

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.

prefire

public boolean prefire()
                throws ptolemy.kernel.util.IllegalActionException
Return false if the input port has no token, otherwise return what the superclass returns (presumably true).

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.