/** Расчет результата */
  public void calculation() {

    if (mathOperation.getTypeMathOperation() == TypeMathOperation.ADD) {
      lastResult = firstNumber + secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.SUB) {
      lastResult = firstNumber - secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.MUL) {
      lastResult = firstNumber * secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.DIV) {

      // try {
      lastResult = firstNumber / secondNumber;
      // } catch (ArithmeticException rte){

      //    lastResult = 0;
      //    textMessage = "div by ZERO";
      //    changed();
      //    return;
      // }

    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.MRC) {
      mrc = lastResult;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.COS) {
      lastResult = (float) Math.cos(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.SIN) {
      lastResult = (float) Math.sin(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.TG) {
      lastResult = (float) Math.tan(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.CT) {
      lastResult = (float) 1 / ((float) Math.tan(firstNumber));
    }

    textMessage = "Result: " + String.valueOf(lastResult);
    changed();
  }
Exemplo n.º 2
0
 @Override
 public Object call(ExecutionContext context, Object self, Object... args) {
   final Double arg = Types.toNumber(context, args[0]).doubleValue();
   if (arg.isInfinite() || arg.isNaN()) {
     return Double.NaN;
   }
   return Math.coerceLongIfPossible(java.lang.Math.tan(arg));
 }
Exemplo n.º 3
0
  // ---------------------------------------------------------------------------
  private String Calculate1(String oper, String str1) throws Exception {
    double n1 = Values.StringToDouble(str1);
    double val = 0;

    if (oper.equalsIgnoreCase("SEN")) val = java.lang.Math.sin(n1);
    else if (oper.equalsIgnoreCase("COS")) val = java.lang.Math.cos(n1);
    else if (oper.equalsIgnoreCase("TAN")) val = java.lang.Math.tan(n1);
    else if (oper.equalsIgnoreCase("CTG")) val = 1.0 / java.lang.Math.tan(n1);
    else if (oper.equalsIgnoreCase("ASEN")) val = java.lang.Math.asin(n1);
    else if (oper.equalsIgnoreCase("ACOS")) val = java.lang.Math.acos(n1);
    else if (oper.equalsIgnoreCase("ATAN")) val = java.lang.Math.atan(n1);
    else if (oper.equalsIgnoreCase("ACTG")) val = 1.0 / java.lang.Math.atan(n1);
    else if (oper.equalsIgnoreCase("SENH")) val = java.lang.Math.sinh(n1);
    else if (oper.equalsIgnoreCase("COSH")) val = java.lang.Math.cosh(n1);
    else if (oper.equalsIgnoreCase("TANH")) val = java.lang.Math.tanh(n1);
    else if (oper.equalsIgnoreCase("CTGH")) val = 1.0 / java.lang.Math.tanh(n1);
    else if (oper.equalsIgnoreCase("EXP")) val = java.lang.Math.exp(n1);
    // valor absoluto de inteiros s�o inteiros
    else if (oper.equalsIgnoreCase("ABS")) {
      val = java.lang.Math.abs(n1);
      if (Values.IsInteger(str1)) return Values.IntegerToString(val);
    } else if (oper.equalsIgnoreCase("RAIZ")) val = java.lang.Math.sqrt(n1);
    else if (oper.equalsIgnoreCase("LOG")) val = java.lang.Math.log10(n1);
    else if (oper.equalsIgnoreCase("LN")) val = java.lang.Math.log(n1);
    // parte inteira do numeros
    else if (oper.equalsIgnoreCase("INT")) {
      return Values.IntegerToString(n1);
    }
    // parte real
    else if (oper.equalsIgnoreCase("FRAC")) {
      String num = Values.DoubleToString(n1);
      return num.substring(num.indexOf('.') + 1);
    }

    // parte real
    else if (oper.equalsIgnoreCase("ARRED")) {
      double vm = java.lang.Math.ceil(n1);
      if (n1 - vm >= 0.5) return Values.IntegerToString((int) n1 + 1);
      return Values.IntegerToString((int) n1);
    } else throw new Exception("ERRO fun��o Desconhecida 1 [" + oper + "]");
    return Values.DoubleToString(val);
  }
Exemplo n.º 4
0
 /* Result is the trigonometric tangent of the angle given by value. The unit of value is radian.
  */
 public static SchemaTypeNumber tan(SchemaTypeNumber value) {
   switch (value.numericType()) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt((int) java.lang.Math.tan(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong((long) java.lang.Math.tan(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(
           (long) java.lang.Math.tan(value.doubleValue())); // note: possible loss of precision
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat((float) java.lang.Math.tan(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(java.lang.Math.tan(value.doubleValue()));
   }
   return new SchemaDecimal(java.lang.Math.tan(value.doubleValue()));
 }
Exemplo n.º 5
0
  private Object interpretFunction(Functions function, Sprite sprite) {
    Object left = null;
    Object right = null;

    Double doubleValueOfLeftChild = null;
    Double doubleValueOfRightChild = null;

    if (leftChild != null) {
      left = leftChild.interpretRecursive(sprite);
      if (left instanceof String) {
        try {
          doubleValueOfLeftChild = Double.valueOf((String) left);
        } catch (NumberFormatException numberFormatException) {
          Log.d(getClass().getSimpleName(), "Couldn't parse String", numberFormatException);
        }
      } else {
        doubleValueOfLeftChild = (Double) left;
      }
    }

    if (rightChild != null) {
      right = rightChild.interpretRecursive(sprite);
      if (right instanceof String) {
        try {
          doubleValueOfRightChild = Double.valueOf((String) right);
        } catch (NumberFormatException numberFormatException) {
          Log.d(getClass().getSimpleName(), "Couldn't parse String", numberFormatException);
        }
      } else {
        doubleValueOfRightChild = (Double) right;
      }
    }

    switch (function) {
      case SIN:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.sin(Math.toRadians(doubleValueOfLeftChild));
      case COS:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.cos(Math.toRadians(doubleValueOfLeftChild));
      case TAN:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.tan(Math.toRadians(doubleValueOfLeftChild));
      case LN:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.log(doubleValueOfLeftChild);
      case LOG:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.log10(doubleValueOfLeftChild);
      case SQRT:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.sqrt(doubleValueOfLeftChild);
      case RAND:
        return (doubleValueOfLeftChild == null || doubleValueOfRightChild == null)
            ? 0d
            : interpretFunctionRand(doubleValueOfLeftChild, doubleValueOfRightChild);
      case ABS:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.abs(doubleValueOfLeftChild);
      case ROUND:
        return doubleValueOfLeftChild == null
            ? 0d
            : (double) java.lang.Math.round(doubleValueOfLeftChild);
      case PI:
        return java.lang.Math.PI;
      case MOD:
        return (doubleValueOfLeftChild == null || doubleValueOfRightChild == null)
            ? 0d
            : interpretFunctionMod(doubleValueOfLeftChild, doubleValueOfRightChild);
      case ARCSIN:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.toDegrees(Math.asin(doubleValueOfLeftChild));
      case ARCCOS:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.toDegrees(Math.acos(doubleValueOfLeftChild));
      case ARCTAN:
        return doubleValueOfLeftChild == null
            ? 0d
            : java.lang.Math.toDegrees(Math.atan(doubleValueOfLeftChild));
      case EXP:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.exp(doubleValueOfLeftChild);
      case POWER:
        return (doubleValueOfLeftChild == null || doubleValueOfRightChild == null)
            ? 0d
            : java.lang.Math.pow(doubleValueOfLeftChild, doubleValueOfRightChild);
      case FLOOR:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.floor(doubleValueOfLeftChild);
      case CEIL:
        return doubleValueOfLeftChild == null ? 0d : java.lang.Math.ceil(doubleValueOfLeftChild);
      case MAX:
        return (doubleValueOfLeftChild == null || doubleValueOfRightChild == null)
            ? 0d
            : java.lang.Math.max(doubleValueOfLeftChild, doubleValueOfRightChild);
      case MIN:
        return (doubleValueOfLeftChild == null || doubleValueOfRightChild == null)
            ? 0d
            : java.lang.Math.min(doubleValueOfLeftChild, doubleValueOfRightChild);
      case TRUE:
        return 1d;
      case FALSE:
        return 0d;
      case LETTER:
        return interpretFunctionLetter(right, left);
      case LENGTH:
        return interpretFunctionLength(left, sprite);
      case JOIN:
        return interpretFunctionJoin(sprite);
      case ARDUINODIGITAL:
        Arduino arduinoDigital =
            ServiceProvider.getService(CatroidService.BLUETOOTH_DEVICE_SERVICE)
                .getDevice(BluetoothDevice.ARDUINO);
        if (arduinoDigital != null && left != null) {
          if (doubleValueOfLeftChild < 0 || doubleValueOfLeftChild > 13) {
            return 0d;
          }
          return arduinoDigital.getDigitalArduinoPin(doubleValueOfLeftChild.intValue());
        }
        break;
      case ARDUINOANALOG:
        Arduino arduinoAnalog =
            ServiceProvider.getService(CatroidService.BLUETOOTH_DEVICE_SERVICE)
                .getDevice(BluetoothDevice.ARDUINO);
        if (arduinoAnalog != null && left != null) {
          if (doubleValueOfLeftChild < 0 || doubleValueOfLeftChild > 5) {
            return 0d;
          }
          return arduinoAnalog.getAnalogArduinoPin(doubleValueOfLeftChild.intValue());
        }
        break;
      case RASPIDIGITAL:
        RPiSocketConnection connection = RaspberryPiService.getInstance().connection;
        int pin = doubleValueOfLeftChild.intValue();
        try {
          return connection.getPin(pin) ? 1d : 0d;
        } catch (Exception e) {
          Log.e(getClass().getSimpleName(), "RPi: exception during getPin: " + e);
        }
        break;
      case MULTI_FINGER_TOUCHED:
        return TouchUtil.isFingerTouching(doubleValueOfLeftChild.intValue()) ? 1d : 0d;
      case MULTI_FINGER_X:
        return Double.valueOf(TouchUtil.getX(doubleValueOfLeftChild.intValue()));
      case MULTI_FINGER_Y:
        return Double.valueOf(TouchUtil.getY(doubleValueOfLeftChild.intValue()));
      case LIST_ITEM:
        return interpretFunctionListItem(left, sprite);
      case CONTAINS:
        return interpretFunctionContains(right, sprite);
      case NUMBER_OF_ITEMS:
        return interpretFunctionNumberOfItems(left, sprite);
    }
    return 0d;
  }
Exemplo n.º 6
0
  private void initStatic() {
    if (initializedTables) {
      return;
    }

    // scale factors table for layer 1/2
    for (int i = 0; i < 64; i++) {
      // 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS
      int shift = i / 3;
      int mod = i % 3;
      scale_factor_modshift[i] = mod | (shift << 2);
    }

    // scale factor multiply for layer 1
    for (int i = 0; i < 15; i++) {
      int n = i + 2;
      int norm = (int) (((1L << n) * FRAC_ONE) / ((1 << n) - 1));
      scale_factor_mult[i][0] = (int) (norm * 1.0f * 2.0f);
      scale_factor_mult[i][1] = (int) (norm * 0.7937005259f * 2.0f);
      scale_factor_mult[i][2] = (int) (norm * 0.6299605249f * 2.0f);
    }

    Mp3Dsp.synthInit(Mp3Dsp.mpa_synth_window);

    // Huffman decode tables
    for (int i = 1; i < 16; i++) {
      HuffTable h = Mp3Data.mpa_huff_tables[i];
      int[] tmpBits = new int[512];
      int[] tmpCodes = new int[512];

      int xsize = h.xsize;

      int j = 0;
      for (int x = 0; x < xsize; x++) {
        for (int y = 0; y < xsize; y++) {
          tmpBits[(x << 5) | y | ((x != 0 && y != 0) ? 16 : 0)] = h.bits[j];
          tmpCodes[(x << 5) | y | ((x != 0 && y != 0) ? 16 : 0)] = h.codes[j++];
        }
      }

      huff_vlc[i] = new VLC();
      huff_vlc[i].initVLCSparse(7, 512, tmpBits, tmpCodes, null);
    }

    for (int i = 0; i < 2; i++) {
      huff_quad_vlc[i] = new VLC();
      huff_quad_vlc[i].initVLCSparse(i == 0 ? 7 : 4, 16, mpa_quad_bits[i], mpa_quad_codes[i], null);
    }

    for (int i = 0; i < 9; i++) {
      int k = 0;
      for (int j = 0; j < 22; j++) {
        band_index_long[i][j] = k;
        k += band_size_long[i][j];
      }
      band_index_long[i][22] = k;
    }

    Mp3Data.tableinit();
    Mp3Dsp.initMpadspTabs();

    for (int i = 0; i < 4; i++) {
      if (mp3_quant_bits[i] < 0) {
        for (int j = 0; j < (1 << (-mp3_quant_bits[i] + 1)); j++) {
          int val = j;
          int steps = Mp3Data.mp3_quant_steps[i];
          int val1 = val % steps;
          val /= steps;
          int val2 = val % steps;
          int val3 = val / steps;
          division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
        }
      }
    }

    for (int i = 0; i < 7; i++) {
      float v;
      if (i != 6) {
        float f = (float) Math.tan(i * Math.PI / 12.0);
        v = f / (1f + f);
      } else {
        v = 1f;
      }
      is_table[0][i] = v;
      is_table[1][6 - i] = v;
    }
    // invalid values
    for (int i = 7; i < 16; i++) {
      is_table[0][i] = 0f;
      is_table[1][i] = 0f;
    }

    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 2; j++) {
        int e = -(j + 1) * ((i + 1) >> 1);
        double f = pow(2.0, e / 4.0);
        int k = i & 1;
        is_table_lsf[j][k ^ 1][i] = (float) f;
        is_table_lsf[j][k][i] = 1f;
      }
    }

    for (int i = 0; i < 8; i++) {
      float ci = ci_table[i];
      float cs = (float) (1.0 / Math.sqrt(1.0 + ci * ci));
      float ca = cs * ci;
      csa_table[i][0] = cs;
      csa_table[i][1] = ca;
      csa_table[i][2] = ca + cs;
      csa_table[i][3] = ca - cs;
    }

    initializedTables = true;
  }
Exemplo n.º 7
0
 public double TAN(double x) {
   return Math.tan(trans(x));
 }
Exemplo n.º 8
0
 @Override
 public double TAN(double x) // 改寫,使得result得以記錄結果
     {
   result = Math.tan(trans(x));
   return result;
 }