Class Round

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class Round
    extends Transformer
    Produce an output token on each firing with a value that is equal to the specified rounded value of the input. The input type is DoubleToken. The output type is IntToken. The functions are a subset of those in the java.lang.Math class. They are:
    • ceil: Round towards positive infinity.
    • floor: Round towards negative infinity.
    • round: Round towards nearest integer. This is the default behavior.
    • truncate: Round towards zero.
    If the input is NaN, then an exception is thrown. The reason for this is that there is no way to represent a NaN as an integer. Thus, even though java.lang.Math.round(Double.NaN) returns 0, ceil(Double.NaN), floor(Double.NaN) and truncate(DoubleNaN) all return a Double.NaN. However, this actor has an integer output, so there is no way to represent the Double.NaN as an integer, so we throw an exception.
    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    C. Fong, Contributor: Christopher Brooks
    Pt.AcceptedRating:
    Green (janneck)
    Pt.ProposedRating:
    Green (chf)
    • Field Detail

      • function

        public StringAttribute function
        The rounding strategy to use. This is a string-valued parameter that defaults to "round".
    • Method Detail

      • iterate

        public int iterate​(int count)
                    throws IllegalActionException
        Invoke a specified number of iterations of this actor. Each iteration computes the rounding function specified by the function attribute on a single token. An invocation of this method therefore applies the function to count successive input tokens.

        This method should be called instead of the usual prefire(), fire(), postfire() methods when this actor is used in a domain that supports vectorized actors. This leads to more efficient execution.

        Specified by:
        iterate in interface Executable
        Overrides:
        iterate in class AtomicActor<TypedIOPort>
        Parameters:
        count - The number of iterations to perform.
        Returns:
        COMPLETED if the actor was successfully iterated the specified number of times. Otherwise, return NOT_READY, and do not consume any input tokens.
        Throws:
        IllegalActionException - Not thrown in this base class.