Esempio n. 1
0
  @Override
  public Operand executeOperation(Stack<Expression> operands) throws ExpressionException {
    if (operands.size() < this.getCurrentOperands())
      throw new ExpressionException("Wrong number of given parameters");

    Apfloat value1 = Operand.extractNumber(operands.pop());

    return new Operand(new Apfloat(value1.intValue()));
  }
 public Apfloat find(Apfloat a, Apfloat b, Apfloat accuracy) {
   accuracy = accuracy.divide(new Apfloat(100));
   Apfloat l2 = new Apfloat(2, Apfloat.INFINITE);
   Apfloat c = new Apfloat(Apfloat.INFINITE);
   int x = 0;
   while (b.subtract(a).compareTo(accuracy) >= 0) {
     x++;
     c = a.add(b).divide(l2);
     // nie uwzględniamy zera!
     // System.out.print(Function1.f(a));
     // System.out.println(Function1.f(c));
     if (Function1.f(a).signum() != Function1.f(c).signum()) {
       b = c;
     } else {
       a = c;
     }
   }
   System.out.println("Ilość kroków w metodzie połowienia wyniosła " + x);
   return c;
 }
 private Apfloat prescaleArg(Apfloat x) {
   return x.divide(new Apfloat("2", precision)).multiply(ApfloatMath.pi(precision));
 }