예제 #1
0
파일: fix.java 프로젝트: donnchadh/jMathLib
  /**
   * rounds the element to the nearest element towards zero.
   *
   * @param operands[0] = value to round
   * @return a matrix of the same size as the operands
   */
  public OperandToken evaluate(Token[] operands) {

    // exactly one operand
    if (getNArgIn(operands) != 1) throwMathLibException("fix: number of arguments != 1");

    // only works on numbers
    if (!(operands[0] instanceof DoubleNumberToken))
      throwMathLibException("fix: only works on numbers");

    DoubleNumberToken matrix = ((DoubleNumberToken) operands[0]);
    OperandToken temp = ((OperandToken) matrix.clone());

    double[][] reValues = matrix.getValuesRe();
    double[][] imValues = matrix.getValuesIm();
    for (int y = 0; y < matrix.getSizeY(); y++) {
      for (int x = 0; x < matrix.getSizeX(); x++) {
        if (reValues[y][x] >= 0) {
          // e.g. fix(3.2) => 3
          reValues[y][x] = java.lang.Math.floor(reValues[y][x]);
        } else {
          // e.g. fix(-3.2) => -3
          reValues[y][x] = java.lang.Math.ceil(reValues[y][x]);
        }
        if (imValues[y][x] >= 0) {
          // e.g. fix(3.2i) => 3
          imValues[y][x] = java.lang.Math.floor(imValues[y][x]);
        } else {
          // e.g. fix(-3.2i) => -3
          imValues[y][x] = java.lang.Math.ceil(imValues[y][x]);
        }
      }
    }
    return new DoubleNumberToken(reValues, imValues);
  }
예제 #2
0
  public OperandToken evaluate(Token[] operands) {

    // exactly one operand
    if (getNArgIn(operands) != 1) throwMathLibException("fix: number of arguments != 1");

    // only works on numbers
    if (!(operands[0] instanceof DoubleNumberToken))
      throwMathLibException("fix: only works on numbers");

    Frame f = new Frame();
    ModalDialog m =
        new ModalDialog(f, "kk", "What do you want?", new String[] {"ok", "not ok", "maybe"});

    // f.show();
    m.show();

    debugLine("questdlg: " + m.str);

    DoubleNumberToken matrix = ((DoubleNumberToken) operands[0]);
    OperandToken temp = ((OperandToken) matrix.clone());

    double[][] reValues = matrix.getValuesRe();
    double[][] imValues = matrix.getValuesIm();
    for (int y = 0; y < matrix.getSizeY(); y++) {
      for (int x = 0; x < matrix.getSizeX(); x++) {
        if (reValues[y][x] >= 0) {
          // e.g. fix(3.2) => 3
          reValues[y][x] = java.lang.Math.floor(reValues[y][x]);
        } else {
          // e.g. fix(-3.2) => -3
          reValues[y][x] = java.lang.Math.ceil(reValues[y][x]);
        }
        if (imValues[y][x] >= 0) {
          // e.g. fix(3.2i) => 3
          imValues[y][x] = java.lang.Math.floor(imValues[y][x]);
        } else {
          // e.g. fix(-3.2i) => -3
          imValues[y][x] = java.lang.Math.ceil(imValues[y][x]);
        }
      }
    }
    return new DoubleNumberToken(reValues, imValues);
  }