public RRaw op(RRaw a, RRaw b, ASTNode ast) {
      int na = a.size();
      int nb = b.size();
      int[] dimensions = Arithmetic.resultDimensions(ast, a, b);
      Names names = Arithmetic.resultNames(ast, a, b);
      if (na == 0 || nb == 0) {
        return RRaw.EMPTY;
      }

      int n = (na > nb) ? na : nb;
      byte[] content = new byte[n];
      int ai = 0;
      int bi = 0;

      for (int i = 0; i < n; i++) {
        byte araw = a.getRaw(ai++);
        if (ai == na) {
          ai = 0;
        }
        byte braw = b.getRaw(bi++);
        if (bi == nb) {
          bi = 0;
        }
        content[i] = op(araw, braw);
      }

      if (ai != 0 || bi != 0) {
        RContext.warning(ast, RError.LENGTH_NOT_MULTI);
      }
      return RRaw.RRawFactory.getFor(content, dimensions, names);
    }
    public RLogical op(RLogical a, RLogical b, ASTNode ast) {
      int na = a.size();
      int nb = b.size();
      int[] dimensions = Arithmetic.resultDimensions(ast, a, b);
      Names names = Arithmetic.resultNames(ast, a, b);
      if (na == 0 || nb == 0) {
        return RLogical.EMPTY;
      }

      int n = (na > nb) ? na : nb;
      int[] content = new int[n];
      int ai = 0;
      int bi = 0;

      for (int i = 0; i < n; i++) {
        int alog = a.getLogical(ai++);
        if (ai == na) {
          ai = 0;
        }
        int blog = b.getLogical(bi++);
        if (bi == nb) {
          bi = 0;
        }
        content[i] = op(alog, blog);
      }

      if (ai != 0 || bi != 0) {
        RContext.warning(ast, RError.LENGTH_NOT_MULTI);
      }
      return RLogical.RLogicalFactory.getFor(content, dimensions, names);
    }
Beispiel #3
0
  /**
   * Returns the modified Bessel function of order 0 of the argument.
   *
   * <p>The function is defined as <tt>i0(x) = j0( ix )</tt>.
   *
   * <p>The range is partitioned into the two intervals [0,8] and (8, infinity). Chebyshev
   * polynomial expansions are employed in each interval.
   *
   * @param x the value to compute the bessel function of.
   */
  public static double i0(double x) throws ArithmeticException {
    double y;
    if (x < 0) x = -x;
    if (x <= 8.0) {
      y = (x / 2.0) - 2.0;
      return (Math.exp(x) * Arithmetic.chbevl(y, A_i0, 30));
    }

    return (Math.exp(x) * Arithmetic.chbevl(32.0 / x - 2.0, B_i0, 25) / Math.sqrt(x));
  }
Beispiel #4
0
  /**
   * Returns the exponentially scaled modified Bessel function of the third kind of order 1 of the
   * argument.
   *
   * <p><tt>k1e(x) = exp(x) * k1(x)</tt>.
   *
   * @param x the value to compute the bessel function of.
   */
  public static double k1e(double x) throws ArithmeticException {
    double y;

    if (x <= 0.0) throw new ArithmeticException();
    if (x <= 2.0) {
      y = x * x - 2.0;
      y = Math.log(0.5 * x) * i1(x) + Arithmetic.chbevl(y, A_k1, 11) / x;
      return (y * Math.exp(x));
    }

    return (Arithmetic.chbevl(8.0 / x - 2.0, B_k1, 25) / Math.sqrt(x));
  }
Beispiel #5
0
  /**
   * Returns the exponentially scaled modified Bessel function of the third kind of order 0 of the
   * argument.
   *
   * @param x the value to compute the bessel function of.
   */
  public static double k0e(double x) throws ArithmeticException {
    double y;

    if (x <= 0.0) throw new ArithmeticException();
    if (x <= 2.0) {
      y = x * x - 2.0;
      y = Arithmetic.chbevl(y, A_k0, 10) - Math.log(0.5 * x) * i0(x);
      return (y * Math.exp(x));
    }

    y = Arithmetic.chbevl(8.0 / x - 2.0, B_k0, 25) / Math.sqrt(x);
    return (y);
  }
Beispiel #6
0
  /**
   * Returns the exponentially scaled modified Bessel function of order 1 of the argument.
   *
   * <p>The function is defined as <tt>i1(x) = -i exp(-|x|) j1( ix )</tt>.
   *
   * @param x the value to compute the bessel function of.
   */
  public static double i1e(double x) throws ArithmeticException {
    double y, z;

    z = Math.abs(x);
    if (z <= 8.0) {
      y = (z / 2.0) - 2.0;
      z = Arithmetic.chbevl(y, A_i1, 29) * z;
    } else {
      z = Arithmetic.chbevl(32.0 / z - 2.0, B_i1, 25) / Math.sqrt(z);
    }
    if (x < 0.0) z = -z;
    return (z);
  }
Beispiel #7
0
 @Test
 public void addTest() {
   Assert.assertEquals(20, a.addition(10, 10), "sum is not equal");
 }