AddSubtract
ptolemy.actor.lib.AddSubtract

A polymorphic adder/subtractor. This adder has two input ports, both of which are multiports, and one output port, which is not. The types on the ports are undeclared and will be resolved by the type resolution mechanism. Data that arrives on the input port named plus will be added, and data that arrives on the input port named minus will be subtracted. Any token type supporting addition and subtraction can be used. In most domains, either input port can be left unconnected. Thus, to get a simple adder (with no subtractor), just leave the minus input unconnected.

The plus input port will typically resolve to the least upper bound of the types presented to it. Thus, for example, if one input channel comes from a source of type BooleanToken and another comes from a source of type IntToken, the resolved type will be StringToken, and addition will be that implemented in StringToken (which concatenates strings). Notice that StringToken does not support subtraction, so if any inputs are presented to the minus port, an exception will be thrown at run time.

Currently, the type system is quite liberal about the resolved types it will permit at the inputs. In particular, it may permit the plus and minus inputs to resolve to types that cannot in fact be subtracted. In these cases, a run-time error will occur. In the future, we hope that the type system will intercept such errors before run time.

This actor does not require that each input channel have a token upon firing. It will add or subtract available tokens at the inputs and ignore the channels that do not have tokens. It consumes at most one input token from each port. If no input tokens are available at all, then no output is produced.

Author(s): Yuhong Xiong and Edward A. Lee
Version:$Id: AddSubtract.java,v 1.37 2005/10/28 19:20:13 cxh Exp $
Pt.Proposed Rating:Green (eal)
Pt.Accepted Rating:Green (bilung)


minus
Input for tokens to be subtracted. This is a multiport, and its type is inferred from the connections.

output
Output port. The type is inferred from the connections.

plus
Input for tokens to be added. This is a multiport, and its type is inferred from the connections.