Esempio n. 1
1
  /**
   * <u>Berechnen des Tangens der komplexen Zahl</u><br>
   *
   * @param comp Komplexe Zahl
   * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus tan(<u>z</u>)
   */
  public static Complex tan(Complex comp) {
    double real, imag;
    double nn =
        1d
            + Math.pow(
                Math.tan(comp.getReal()) * Math.tanh(comp.getImag()), 2); // Nenner der Brueche

    real = (Math.tan(comp.getReal()) * (1 - Math.pow(Math.tanh(comp.getImag()), 2))) / nn;
    imag = (Math.tanh(comp.getImag()) * (1 + Math.pow(Math.tan(comp.getReal()), 2))) / nn;

    return new Complex(real, imag);
  }
Esempio n. 2
1
 public static final Color fromDouble(double v) {
   // inf = 255 255 0 yellow
   // 1 = 0 255 0 green
   // 0 = 0 0 0 black
   // -1 = 255 0 0 red
   // -inf = 255 0 255 magenta
   // nan = 0 255 255 cyan
   if (v == Double.MIN_VALUE || Double.isNaN(v)) return (Color.MAGENTA);
   else if (Double.isInfinite(v)) return (Color.CYAN);
   else if (v > 1.0)
     return (ColorMap.colorGreenToYellow[(int) (255.0 * Math.tanh((v - 1.0) / 10.0))]);
   else if (v > 0.0) return (ColorMap.colorBlackToGreen[(int) (255.0 * v)]);
   else if (v > -1.0) return (ColorMap.colorRedToBlack[(int) (255.0 * (v + 1.0))]);
   else return (ColorMap.colorRedToMagenta[(int) (255.0 * Math.tanh((-v - 1.0) / 10.0))]);
 }
Esempio n. 3
0
 /**
  * @param M
  * @return
  */
 public static Matrix tanh(Matrix M) {
   float[] a = M.getData();
   for (int i = 0; i < a.length; i++) {
     a[i] = (float) Math.tanh(a[i]);
   }
   return new Matrix(a, M.m, M.n);
 }
Esempio n. 4
0
 @Test
 public void testTanh() {
   for (double doubleValue : DOUBLE_VALUES) {
     assertFunction("tanh(" + doubleValue + ")", DOUBLE, Math.tanh(doubleValue));
   }
   assertFunction("tanh(NULL)", DOUBLE, null);
 }
  private static double checkXorFitness(Function xorAttempt, int waveCount)
      throws CloneNotSupportedException {
    if (waveCount <= 0) throw new IllegalArgumentException("waveCount must be >0");

    // testing against xor at 4 points only (0,0 0,1 1,0 1,1)
    xorAttempt.setParameter(0, 0.0);
    xorAttempt.setParameter(1, 0.0);
    final double result00 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 1.0);
    xorAttempt.setParameter(1, 0.0);
    final double result10 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 0.0);
    xorAttempt.setParameter(1, 1.0);
    final double result01 = xorAttempt.calculate();

    xorAttempt.setParameter(0, 1.0);
    xorAttempt.setParameter(1, 1.0);
    final double result11 = xorAttempt.calculate();

    // calculates the whole number portion of the fitness, should be between -4 and +4
    final int fitnessWhole =
        (result00 < 0.0 ? 1 : 0)
            + (result10 > 0.0 ? 1 : 0)
            + (result01 > 0.0 ? 1 : 0)
            + (result11 < 0.0 ? 1 : 0);

    // calculates the decimal portion of the fitness , should be >= 0 and < 1
    final double fitnessFine = 1.0 - Math.tanh(waveCount);

    return ((double) fitnessWhole) + fitnessFine;
  }
 /** {@inheritDoc} */
 public OpenMapRealVector mapTanhToSelf() {
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     entries.put(iter.key(), Math.tanh(iter.value()));
   }
   return this;
 }
Esempio n. 7
0
 // rager method of ibu calculation
 // constant 7962 is corrected to 7490 as per hop faq
 public static double CalcRager(double amount, double size, double sg, double time, double AA) {
   double ibu, utilization, ga;
   utilization = 18.11 + 13.86 * Math.tanh((time - 31.32) / 18.27);
   ga = sg < 1.050 ? 0.0 : ((sg - 1.050) / 0.2);
   ibu = amount * (utilization / 100) * (AA / 100.0) * 7490;
   ibu /= size * (1 + ga);
   return ibu;
 }
 static final double calcSmoothFraction(double speedMe, double speedFront) {
   final double widthDeltaSpeed = 1; // parameter
   double x = 0; // limiting case: consider only acceleration in vehicle's lane
   if (speedFront >= 0) {
     x = 0.5 * (1 + Math.tanh((speedMe - speedFront) / widthDeltaSpeed));
   }
   return x;
 }
  @Override
  public void loop(RobotContext ctx, LinkedList<Object> out) throws Exception {
    PolarCoordinates joystick = gamepad1().rightJoystick().polar().invert();
    double r = joystick.getR();
    r = Range.clip(2.2842 * Math.pow(Math.tanh(r), 3d), -1, 1);
    joystick = new PolarCoordinates(r, joystick.getTheta());

    // TODO: finish this
  }
Esempio n. 10
0
 public static double getValue(BoardGame game, Player player) {
   if (game.endOfGame()) {
     int result;
     if (game.getOutcome() > 0) {
       result = 1;
     } else if (game.getOutcome() < 0) {
       result = -1;
     } else {
       result = 0;
     }
     return result;
   } else {
     return Math.tanh(player.evaluate(game.getBoard()));
   }
 }
  protected void updateGeometry(Hole hole) {
    mRB = hole.getBoreDiameter() / 2.;
    mRH = 0.912 * hole.getDiameter() / 2.; // Multiplier set by eye to fit LightG6HoleNaf tuning.
    mLH = hole.getHeight();
    mRC = hole.getInnerCurvatureRadius() == null ? 0.0005 : hole.getInnerCurvatureRadius();
    double rh_on_rb = mRH / mRB;
    double rh_on_rb_2 = rh_on_rb * rh_on_rb;
    double rh_on_rb_4 = rh_on_rb_2 * rh_on_rb_2;

    double term1 = 0.47 * mRH * rh_on_rb_4;
    double term2 = 0.62 * rh_on_rb_2 + 0.64 * rh_on_rb;
    double term3 = Math.tanh(1.84 * mLH / mRH);

    // From eq. (8) in Keefe (1990):
    mOHLB = term1 / (term2 + term3);
    // From eq. (9) in Keefe (1990):
    mCHLB = term1 / (term2 + (1.0 / term3));
  }
Esempio n. 12
0
  static void partrans(int p, double[] raw, double[] newdata) {
    int j, k;
    double a;
    int n = 0;
    if (raw.length > newdata.length) {
      n = raw.length;
    } else {
      n = newdata.length;
    }
    double work[] = new double[n];

    //	    if(p > 100) error(_("can only transform 100 pars in arima0"));

    for (j = 0; j < p; j++) work[j] = newdata[j] = Math.tanh(raw[j]);

    for (j = 1; j < p; j++) {
      a = newdata[j];
      for (k = 0; k < j; k++) work[k] -= a * newdata[j - k - 1];
      for (k = 0; k < j; k++) newdata[k] = work[k];
    }
  }
Esempio n. 13
0
 public LuaValue call(LuaValue arg) {
   switch (opcode) {
     case 0:
       return valueOf(Math.acos(arg.checkdouble()));
     case 1:
       return valueOf(Math.asin(arg.checkdouble()));
     case 2:
       return valueOf(Math.atan(arg.checkdouble()));
     case 3:
       return valueOf(Math.cosh(arg.checkdouble()));
     case 4:
       return valueOf(Math.exp(arg.checkdouble()));
     case 5:
       return valueOf(Math.log(arg.checkdouble()));
     case 6:
       return valueOf(Math.log10(arg.checkdouble()));
     case 7:
       return valueOf(Math.sinh(arg.checkdouble()));
     case 8:
       return valueOf(Math.tanh(arg.checkdouble()));
   }
   return NIL;
 }
Esempio n. 14
0
 @Override
 public double apply(double x) {
   return Math.tanh(x);
 }
Esempio n. 15
0
    public void fcn(int m, int n, double[] x, double[] fvec, double[][] fjac, int iflag[]) {
      if (x[2] <= 0.0) {
        final double BIG = 1.0e100;
        fvec[1] = BIG;
        fvec[2] = BIG;
        fjac[1][1] = BIG;
        fjac[1][2] = 0.0;
        fjac[2][1] = 0.0;
        fjac[2][2] = BIG;
        return;
      }

      double sum;
      double prod;

      if (iflag[1] == 1) {
        sum = 0.0;
        for (int i = 0; i < n; i++) sum += (1.0 / (1.0 + Math.exp(x[2] * (xi[i] - x[1]))));
        fvec[1] = sum - n / 2.0;

        sum = 0.0;
        for (int i = 0; i < n; i++) {
          prod = x[2] * (xi[i] - x[1]);
          sum -= prod * Math.tanh(prod / 2.0);
        }
        fvec[2] = sum - n;
      } else if (iflag[1] == 2) {
        sum = 0.0;
        for (int i = 0; i < n; i++) {
          prod = Math.exp(x[2] * (xi[i] - x[1]));
          sum -= x[2] * prod / ((1 + prod) * (1 + prod));
        }
        fjac[1][1] = sum;

        sum = 0.0;
        for (int i = 0; i < n; i++) {
          prod = Math.exp(x[2] * (xi[i] - x[1]));
          sum -= (xi[i] - x[1]) * prod / ((1 + prod) * (1 + prod));
        }
        fjac[1][2] = sum;

        sum = 0.0;
        for (int i = 0; i < n; i++) {
          prod = Math.exp(x[2] * (xi[i] - x[1]));
          sum -=
              (x[2] * ((-1.0 + prod) * (1.0 + prod) - (2.0 * (x[2] * (xi[i] - x[1])) * prod)))
                  / ((1.0 + prod) * (1.0 + prod));
        }
        fjac[2][1] = sum;

        sum = 0.0;
        for (int i = 0; i < n; i++) {
          prod = Math.exp(x[2] * (xi[i] - x[1]));
          sum -=
              ((x[1] - xi[1])
                      * ((-1.0 + prod) * (1.0 + prod) - (2.0 * (x[2] * (xi[i] - x[1])) * prod)))
                  / ((1.0 + prod) * (1.0 + prod));
        }
        fjac[2][2] = sum;
      }
    }
Esempio n. 16
0
  /**
   * Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m), and dn(u|m) of parameter m between
   * 0 and 1, and real argument u. (based on the function from the Cephes Math Library)
   *
   * @param u
   * @param m
   * @return an array containing the values of the functions sn(u|m), cn(u|m), dn(u|m) and phi, the
   *     amplitude of u
   */
  public static double[] calculateJacobianEllipticFunctionsValues(double u, double m) {

    double ai, b, phi, t, twon;
    double sn, cn, ph, dn;
    double[] a = new double[9];
    double[] c = new double[9];
    int i;

    // Check for special cases
    if (m < 0.0 || m > 1.0 || Double.isNaN(m))
      throw new IllegalArgumentException("m should be in <0,1>");
    if (m < 1.0e-9) {

      t = Math.sin(u);
      b = Math.cos(u);
      ai = 0.25 * m * (u - t * b);
      sn = t - ai * b;
      cn = b + ai * t;
      ph = u - ai;
      dn = 1.0 - 0.5 * m * t * t;
      return new double[] {sn, cn, dn, ph};
    }
    if (m >= 0.9999999999) {
      ai = 0.25 * (1.0 - m);
      b = Math.cosh(u);
      t = Math.tanh(u);
      phi = 1.0 / b;
      twon = b * Math.sinh(u);

      sn = t + ai * (twon - u) / (b * b);
      ph = 2.0 * Math.atan(Math.exp(u)) - Math.PI / 2 + ai * (twon - u) / b;
      ai *= t * phi;
      cn = phi - ai * (twon - u);
      dn = phi + ai * (twon + u);
      return new double[] {sn, cn, dn, ph};
    }

    //	A. G. M. scale
    a[0] = 1.0;
    b = Math.sqrt(1.0 - m);
    c[0] = Math.sqrt(m);
    twon = 1.0;
    i = 0;

    while (Math.abs(c[i] / a[i]) > getMachineEpsilon()) {

      if (i > 7)
        throw new IllegalArgumentException(
            "Jacobian elliptic functions cannot be calculated due to overflow range error");
      ai = a[i];
      i++;
      c[i] = (ai - b) / 2.0;
      t = Math.sqrt(ai * b);
      a[i] = (ai + b) / 2.0;
      b = t;
      twon *= 2.0;
    }

    // backward recurrence
    phi = twon * a[i] * u;
    do {

      t = c[i] * Math.sin(phi) / a[i];
      b = phi;
      phi = (Math.asin(t) + phi) / 2.0;
      i--;

    } while (i > 0);

    sn = Math.sin(phi);
    t = Math.cos(phi);
    cn = t;
    dn = t / Math.cos(phi - b);
    ph = phi;

    return new double[] {sn, cn, dn, ph};
  }
Esempio n. 17
0
    public int core_algo() // decides whether to run stuff locally or in a distributed manner
          // returns the value of best NUMBER OF DEVICES to be used. NOT NUMBER OF CLIENTS
        {

      // first get all possible frequencies available in the device
      try {
        // FileInputStream fin=new
        // FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies");
        // FileInputStream finv=new
        // FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
        FileInputStream fin = new FileInputStream("/storage/sdcard0/scaling_available_frequencies");
        FileInputStream finv = new FileInputStream("/storage/sdcard0/uvmv_table");

        BufferedReader br = new BufferedReader(new InputStreamReader(fin));
        BufferedReader brv = new BufferedReader(new InputStreamReader(finv));
        String line = br.readLine();
        String linev = new String("");
        StringTokenizer data = new StringTokenizer(line, " ");
        double c = 0.0055;
        frequencies = new int[data.countTokens()];
        int i = 0;
        while (data.hasMoreElements()) {
          frequencies[i++] = Integer.parseInt(data.nextToken().toString());
        }
        // now read from uvmv table
        while ((linev = brv.readLine()) != null) {
          StringTokenizer stv = new StringTokenizer(linev, ":");
          // now split stv[0] with the letter m as the splitter because it's usually like 1400mhz:
          // 1450 mv
          StringTokenizer stv0 = new StringTokenizer(stv.nextElement().toString(), "m");
          int uvmv_frequency = Integer.parseInt(stv0.nextElement().toString());
          StringTokenizer stv1 = new StringTokenizer(stv.nextElement().toString(), " ");
          int uvmv_voltage = Integer.parseInt(stv1.nextElement().toString());
          uvmv.put(new Integer(uvmv_frequency), new Double(uvmv_voltage));
          System.out.println(uvmv_frequency + ":" + uvmv_voltage);
        }
        fmax =
            frequencies[
                0]; // because in these kernels, the frequencies are listed in descending order

        double D = pixels.length * 4 / Math.pow(2, 20);

        // now iterate over all the frequency steps that the server has
        int dt = 0; // for decisiontable
        for (int ctr = 1;
            ctr < frequencies.length - 2;
            ctr++) // starting at ctr=1 because ctr=0 implies no clients and only server
        {
          double f = frequencies[ctr];

          for (int n = 2; n <= no_of_clients + 1; n++) // here n is for number of devices
          {
            double x = (f / fmax);
            System.out.println("x is " + x);
            double fclient =
                getClosestFrequency(
                    (1 - x) * fmax
                        / (n
                            - 1)); // assuming that all servers and clients run same kernel, fmax
                                   // and fmaxclient are the same
            // fmax and f and fclient are in hertz
            System.out.println("fclient is " + fclient);
            double Ec = (1 - x) * D * ((n + 1) + 1.989);
            double Tc = (2060 + 2028 * (1 - x) * D) / Math.tanh(n - 1.122);

            double latencydiff = (x * D / f) + Tc + ((1 - x) * D / fclient) - (D / fmax);

            double ediff =
                (c * Math.pow(uvmv.get((int) f / 1000) / 1000, 2) * x * D * Math.pow(2, 20)) / 150
                    + Ec
                    + ((1 - x)
                            * D
                            * Math.pow(2, 20)
                            * c
                            * Math.pow(uvmv.get((int) fclient / 1000) / 1000, 2))
                        / 150
                    - (D * Math.pow(2, 20) * c * Math.pow(uvmv.get((int) fmax / 1000) / 1000, 2))
                        / 150;

            // dividing by 1000 in the uvmv.get statements because they are expressed in mhz in the
            // uvmv table.
            double ediffratio =
                ediff / (D * Math.pow(2, 20) * c * Math.pow(uvmv.get((int) fmax / 1000) / 1000, 2));
            double ldiffratio = latencydiff / (D / fmax);
            System.out.println(
                "ediff is "
                    + ediff
                    + " ad Ec is "
                    + Ec
                    + " and ediffratio is "
                    + ediffratio
                    + " and latency diff is "
                    + latencydiff
                    + " and ldiffratio is "
                    + ldiffratio);

            if (ediff < 0) // means that energy has been saved
            {
              decisiontable[dt] = new double[8];
              decisiontable[dt][0] = n;
              decisiontable[dt][1] = fclient;
              decisiontable[dt][2] = f;
              decisiontable[dt][3] = latencydiff;
              decisiontable[dt][4] = ediff;
              decisiontable[dt][5] = ediffratio;
              decisiontable[dt][6] = ldiffratio;
              decisiontable[dt++][7] = x;
              System.out.println(n + " devices entry made in dt ");
              System.out.println(" ");
              // System.out.println(" ");
            }
          }
        }

        // now the loop is over. iterate over decisiontable and choose such that energy is
        // minimized.
        double min = decisiontable[0][4];

        for (int j = 0; j < dt; j++) {
          // System.out.println("The ediff value is "+decisiontable[j][4]);
          if (decisiontable[j][4] < min) {
            min = decisiontable[j][4];
            index = j;
          }
        }

        // facebook hackathon changes
        decisiontable[dt] = new double[8];
        decisiontable[dt][0] = no_of_clients;
        decisiontable[dt][1] = 800;
        decisiontable[dt][2] = 1000;
        decisiontable[dt][3] = decisiontable[index][3];
        decisiontable[dt][4] = decisiontable[index][4];
        decisiontable[dt][5] = decisiontable[index][5];
        decisiontable[dt][6] = decisiontable[index][6];
        decisiontable[dt][7] = 1000 / fmax;
        index = dt++;

        // now index stores the configuration that we need to use
        System.out.println(
            "Winning x value is "
                + decisiontable[index][7]
                + " and ediff is "
                + decisiontable[index][4]
                + "The client is being set to"
                + decisiontable[index][1]);

        // now set server frequency
        // setServerFrequency((int)getClosestFrequency(decisiontable[index][2]));//commented out for
        // facebook hackathon
      } catch (Exception e) {
        e.printStackTrace();
      }
      return (int) (decisiontable[index][0]);
    }
Esempio n. 18
0
 protected double call(double d) {
   return Math.tanh(d);
 }
Esempio n. 19
0
 void activate() {
   for (int i = 0; i < net.length; i++) {
     activation[i] = Math.tanh(net[i]);
   }
 }
Esempio n. 20
0
 public RealNumber tanh() {
   return new RealNumber(Math.tanh(this.value));
 }
Esempio n. 21
0
 private double tanHActivation(double input, double factor) {
   return Math.tanh(factor * input);
 }
Esempio n. 22
0
 @Description("hyperbolic tangent")
 @ScalarFunction
 @SqlType(DoubleType.NAME)
 public static double tanh(@SqlType(DoubleType.NAME) double num) {
   return Math.tanh(num);
 }
Esempio n. 23
0
 @Override
 public double evalute(double value) {
   return Math.tanh(value);
 }
Esempio n. 24
0
 @Override
 public double compute(double x) {
   return 1.7159 * Math.tanh(0.66666667 * x);
   //        return Math.tanh(x);
 }
Esempio n. 25
0
 protected void tanh(double[] array) {
   for (int i = 0; i < array.length; i++) {
     array[i] = Math.tanh(array[i]);
   }
 }
 // To add/remove functions change evaluateOperator() and registration
 public double evaluateFunction(String fncnam, ArgParser fncargs) throws ArithmeticException {
   switch (Character.toLowerCase(fncnam.charAt(0))) {
     case 'a':
       {
         if (fncnam.equalsIgnoreCase("abs")) {
           return Math.abs(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("acos")) {
           return Math.acos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("asin")) {
           return Math.asin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("atan")) {
           return Math.atan(fncargs.next());
         }
       }
       break;
     case 'c':
       {
         if (fncnam.equalsIgnoreCase("cbrt")) {
           return Math.cbrt(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("ceil")) {
           return Math.ceil(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cos")) {
           return Math.cos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cosh")) {
           return Math.cosh(fncargs.next());
         }
       }
       break;
     case 'e':
       {
         if (fncnam.equalsIgnoreCase("exp")) {
           return Math.exp(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("expm1")) {
           return Math.expm1(fncargs.next());
         }
       }
       break;
     case 'f':
       {
         if (fncnam.equalsIgnoreCase("floor")) {
           return Math.floor(fncargs.next());
         }
       }
       break;
     case 'g':
       {
         //              if(fncnam.equalsIgnoreCase("getExponent"   )) { return
         // Math.getExponent(fncargs.next());                } needs Java 6
       }
       break;
     case 'l':
       {
         if (fncnam.equalsIgnoreCase("log")) {
           return Math.log(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log10")) {
           return Math.log10(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log1p")) {
           return Math.log1p(fncargs.next());
         }
       }
       break;
     case 'm':
       {
         if (fncnam.equalsIgnoreCase("max")) {
           return Math.max(fncargs.next(), fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("min")) {
           return Math.min(fncargs.next(), fncargs.next());
         }
       }
       break;
     case 'n':
       {
         //              if(fncnam.equalsIgnoreCase("nextUp"        )) { return Math.nextUp
         // (fncargs.next());                } needs Java 6
       }
       break;
     case 'r':
       {
         if (fncnam.equalsIgnoreCase("random")) {
           return Math.random();
         } // impure
         if (fncnam.equalsIgnoreCase("round")) {
           return Math.round(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("roundHE")) {
           return Math.rint(fncargs.next());
         } // round half-even
       }
       break;
     case 's':
       {
         if (fncnam.equalsIgnoreCase("signum")) {
           return Math.signum(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sin")) {
           return Math.sin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sinh")) {
           return Math.sinh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sqrt")) {
           return Math.sqrt(fncargs.next());
         }
       }
       break;
     case 't':
       {
         if (fncnam.equalsIgnoreCase("tan")) {
           return Math.tan(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("tanh")) {
           return Math.tanh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toDegrees")) {
           return Math.toDegrees(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toRadians")) {
           return Math.toRadians(fncargs.next());
         }
       }
       break;
     case 'u':
       {
         if (fncnam.equalsIgnoreCase("ulp")) {
           return Math.ulp(fncargs.next());
         }
       }
       break;
       // no default
   }
   throw new UnsupportedOperationException(
       "MathEval internal function setup is incorrect - internal function \""
           + fncnam
           + "\" not handled");
 }
 /**
  * Prevents that the updating of the network happens too abrupt
  *
  * @param x the value where the hyperTan is going to be calculated for
  * @return hyperTan
  */
 private static double hyperTanFunction(double x) {
   if (x < -45.0) return -1.0;
   if (x > 45.0) return 1.0;
   return Math.tanh(x);
 }
Esempio n. 28
0
 public static IntervalDouble math_tanh(IntervalDouble a) {
   IntervalDouble res =
       new IntervalDouble(Math.tanh(a.value), DoubleInterval.tanh(a.interval), a.isUnStable);
   return res;
 }
Esempio n. 29
0
  @Override
  public Object visit(RealUnaryExpression n, Void arg) {
    Double doubleObject = (Double) n.getOperand().accept(this, null);
    double doubleVal = doubleObject.doubleValue();

    Operator op = n.getOperator();
    switch (op) {
      case ABS:
        return Math.abs(doubleVal);
      case ACOS:
        return Math.acos(doubleVal);
      case ASIN:
        return Math.asin(doubleVal);
      case ATAN:
        return Math.atan(doubleVal);
      case CBRT:
        return Math.cbrt(doubleVal);
      case CEIL:
        return Math.ceil(doubleVal);
      case COS:
        return Math.cos(doubleVal);
      case COSH:
        return Math.cosh(doubleVal);
      case EXP:
        return Math.exp(doubleVal);
      case EXPM1:
        return Math.expm1(doubleVal);
      case FLOOR:
        return Math.floor(doubleVal);
      case LOG:
        return Math.log(doubleVal);
      case LOG10:
        return Math.log10(doubleVal);
      case LOG1P:
        return Math.log1p(doubleVal);
      case NEG:
        return -doubleVal;
      case NEXTUP:
        return Math.nextUp(doubleVal);
      case RINT:
        return Math.rint(doubleVal);
      case SIGNUM:
        return Math.signum(doubleVal);
      case SIN:
        return Math.sin(doubleVal);
      case SINH:
        return Math.sinh(doubleVal);
      case SQRT:
        return Math.sqrt(doubleVal);
      case TAN:
        return Math.tan(doubleVal);
      case TANH:
        return Math.tanh(doubleVal);
      case TODEGREES:
        return Math.toDegrees(doubleVal);
      case TORADIANS:
        return Math.toRadians(doubleVal);
      case ULP:
        return Math.ulp(doubleVal);

      default:
        log.warn("RealUnaryExpression: unimplemented operator: " + op);
        return null;
    }
  }