コード例 #1
0
ファイル: Remainder.java プロジェクト: ptII/ptII
 /**
  * Consume at most one input token and output the remainder after dividing the input by the
  * divisor. If there is no input token, then no output is produced.
  *
  * @exception IllegalActionException If there is no director.
  */
 public void fire() throws IllegalActionException {
   super.fire();
   if (input.hasToken(0)) {
     double in = ((DoubleToken) input.get(0)).doubleValue();
     double divisorValue = ((DoubleToken) divisor.getToken()).doubleValue();
     output.send(0, new DoubleToken(Math.IEEEremainder(in, divisorValue)));
   }
 }
コード例 #2
0
  /**
   * Consume at most one token from the input port and produce the element at the index specified by
   * this token from the table array on the output port. If there is no token on the input or the
   * token is out of range, then no output is produced.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    if (input.hasToken(0)) {
      ArrayToken token = (ArrayToken) table.getToken();

      if (token != null) {
        int indexValue = ((IntToken) input.get(0)).intValue();

        if ((indexValue >= 0) && (indexValue < token.length())) {
          output.broadcast(token.getElement(indexValue));
        }
      }
    }
  }
コード例 #3
0
ファイル: Scale.java プロジェクト: ptII/ptII
  /**
   * Compute the product of the input and the <i>factor</i>. If there is no input, then produce no
   * output.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    if (input.hasToken(0)) {
      Token in = input.get(0);
      Token factorToken = factor.getToken();
      Token result;

      if (((BooleanToken) scaleOnLeft.getToken()).booleanValue()) {
        // Scale on the left.
        result = factorToken.multiply(in);
      } else {
        // Scale on the right.
        result = in.multiply(factorToken);
      }
      output.send(0, result);
    }
  }