Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

In this page you can find the example usage for java.lang Math pow.

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:knop.psfj.utils.MathUtils.java

/**
 * Round./*ww  w.  j  av a2 s  .co m*/
 *
 * @param nb2round the nb2round
 * @param nbOfDigits the nb of digits
 * @return the double
 */
public static double round(double nb2round, int nbOfDigits) {
    return Math.round(nb2round * Math.pow(10, nbOfDigits)) / Math.pow(10, nbOfDigits);
}

From source file:IntUtils.java

public static int BytesToInt(byte[] bArr) {
    int cnt = 0, num = 0;

    for (int i = bArr.length - 1; i >= 0; i--) {
        num += (bArr[i] - 48) * ((int) Math.pow(10, cnt++));
    }/* w ww.  ja  va  2  s . c  o m*/

    return num;
}

From source file:net.anthonypoon.fintech.assignment.one.part2.Portfolio.java

public Portfolio(String name, List<Stock> stockList, Index index, double riskFreeR) {
    this.name = name;
    // dereference the list
    for (Stock stock : stockList) {
        this.stockList.add(new Stock(stock));
    }// w w  w  .  j  av a2 s . c o  m
    this.riskFreeR = riskFreeR;
    this.refIndex = index;
    this.marketVar = Math.pow(refIndex.getStd(), 2);
    for (Stock stock : this.stockList) {
        stock.setExReturn(stock.getRate() - riskFreeR);
        SimpleRegression regress = new SimpleRegression();
        List<Double> stockRList = stock.getRList();
        List<Double> indexRList = index.getRList();
        for (int i = 0; i < stockRList.size(); i++) {
            regress.addData(indexRList.get(i), stockRList.get(i));
        }
        stock.setAlpha(regress.getIntercept());
        stock.setBeta(regress.getSlope());
        stock.setEK(Math.sqrt(
                Math.pow(stock.getStd(), 2) - Math.pow(regress.getSlope(), 2) * Math.pow(index.getStd(), 2)));
    }
}

From source file:com.itemanalysis.psychometrics.rasch.ScaleQualityStatistics.java

public void increment(double estimate, double stdError) {
    var.increment(estimate);
    mean.increment(Math.pow(stdError, 2));
}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiNormalBhattacharyyaDistanceScore.java

@Override
public double score(double[][][] input) {

    Mean mean = new Mean();
    Variance var = new Variance();

    double mu0, sigs0, mu1, sigs1;
    double dist[][] = new double[2][];

    dist[0] = MatrixUtils.createRealMatrix(input[0]).getColumn(0);
    dist[1] = MatrixUtils.createRealMatrix(input[1]).getColumn(0);

    mu0 = mean.evaluate(dist[0]);//from  www.j  ava 2 s .  c o  m
    sigs0 = var.evaluate(dist[0]) + Double.MIN_VALUE;
    mu1 = mean.evaluate(dist[1]);
    sigs1 = var.evaluate(dist[1]) + Double.MIN_VALUE;

    double distance = (Math.log((sigs0 / sigs1 + sigs1 / sigs0 + 2) / 4)
            + (Math.pow(mu1 - mu0, 2.0) / (sigs0 + sigs1))) / 4;

    return distance == Double.POSITIVE_INFINITY ? 0 : distance;

}

From source file:ufmotionsuite.SpiralGraph.java

public void getData(double[] x, double[] y, int length, double[] theta1) {
    for (int i = 0; i < length; i++) {
        xCoord[i] = x[i];//from  ww w. j av a2  s  . c o m
        yCoord[i] = y[i];
    }
    arrLength = length;

    for (int i = 3; i < arrLength; i++) {
        //CHANGE TO BE DISTANCE FROM ORIGIN TO POINT
        r[i] = Math.sqrt(Math.pow(xCoord[i] - xCoord[2], 2.0) + Math.pow(yCoord[i] - yCoord[2], 2.0));
        theta[i] = theta1[i];
        System.out.println("R is: " + r[i]);
        System.out.println(" Theta is: " + theta[i]);
    }

    Graph();

}

From source file:Main.java

public static int nextExp2(int n) {

    double e = Math.log((double) n) / Math.log(2.0);
    int p = (int) Math.ceil(e);
    double f = n / Math.pow(2.0, (double) p);
    if (f == 0.5) {
        p = p - 1;//from  w  w  w. ja  va  2 s. c om
    }
    return p;
}

From source file:Main.java

/** This method returns the largest double value that is smaller than
 * <code> d = x * 10<sup>exp</sup></code> where x is rounded down to
 * the closest integer.//from   w ww. ja  v  a 2s. co  m
 * @param d the double value to be rounded
 * @param exp the exponent of 10 to which d should be rounded
 * @return <code> Math.floor(x) * 10<sup>exp</sup></code>
 */
public static double floor(double d, int exp) {
    double x = 1.0 * Math.pow(10.0, (double) exp);

    return Math.floor(d / x) * x;
}

From source file:com.opengamma.analytics.math.function.special.OrthonormalHermitePolynomialFunctionTest.java

@Test
public void test() {
    final int n = 15;
    final DoubleFunction1D[] f1 = HERMITE.getPolynomials(n);
    final DoubleFunction1D[] f2 = ORTHONORMAL.getPolynomials(n);
    final double x = 3.4;
    for (int i = 0; i < f1.length; i++) {
        assertEquals(//w w w  .j  a v  a 2 s  . c  o m
                f1[i].evaluate(x)
                        / Math.sqrt(MathUtils.factorialDouble(i) * Math.pow(2, i) * Math.sqrt(Math.PI)),
                f2[i].evaluate(x), EPS);
    }
}

From source file:Main.java

private static int getDoubleChars(double number, char[] buf, int charPos, int significantDigits) {
    if (number != number) {
        STR_NAN.getChars(0, STR_NAN_LEN, buf, charPos);
        return charPos + STR_NAN_LEN;
    }/*from w  w  w  .j  ava2 s.c  om*/

    //we need to detect -0.0 to be compatible with JDK
    boolean negative = (Double.doubleToRawLongBits(number) & 0x8000000000000000L) != 0;
    if (negative) {
        buf[charPos++] = '-';
        number = -number;
    }

    if (number == Double.POSITIVE_INFINITY) {
        STR_INFINITY.getChars(0, STR_INFINITY_LEN, buf, charPos);
        return charPos + STR_INFINITY_LEN;
    }

    if (number == 0) {
        buf[charPos++] = '0';
        buf[charPos++] = '.';
        buf[charPos++] = '0';
    } else {
        int exponent = 0;

        // calc. the power (base 10) for the given number:
        int pow = (int) Math.floor(Math.log(number) / LN10);

        // use exponential formatting if number too big or too small
        if (pow < -3 || pow > 6) {
            exponent = pow;
            number /= Math.exp(LN10 * exponent);
        } // if

        // Recalc. the pow if exponent removed and d has changed
        pow = (int) Math.floor(Math.log(number) / LN10);

        // Decide how many insignificant zeros there will be in the
        // lead of the number.
        int insignificantDigits = -Math.min(0, pow);

        // Force it to start with at least "0." if necessarry
        pow = Math.max(0, pow);
        double divisor = Math.pow(10, pow);

        // Loop over the significant digits (17 for double, 8 for float)
        for (int i = 0, end = significantDigits + insignificantDigits, div; i < end; i++) {

            // Add the '.' when passing from 10^0 to 10^-1
            if (pow == -1) {
                buf[charPos++] = '.';
            } // if

            // Find the divisor
            div = (int) (number / divisor);
            // This might happen with 1e6: pow = 5 ( instead of 6 )
            if (div == 10) {
                buf[charPos++] = '1';
                buf[charPos++] = '0';
            } // if
            else {
                buf[charPos] = (char) (div + '0');
                charPos++;
            } // else

            number -= div * divisor;
            divisor /= 10.0;
            pow--;

            // Break the loop if we have passed the '.'
            if (number == 0 && divisor < 0.1)
                break;
        } // for

        // Remove trailing zeros
        while (buf[charPos - 1] == '0')
            charPos--;

        // Avoid "4." instead of "4.0"
        if (buf[charPos - 1] == '.')
            charPos++;
        if (exponent != 0) {
            buf[charPos++] = 'E';
            if (exponent < 0) {
                buf[charPos++] = '-';
                exponent = -exponent;
            }
            if (exponent >= 100)
                buf[charPos++] = (char) (exponent / 100 + '0');
            if (exponent >= 10)
                buf[charPos++] = (char) (exponent / 10 % 10 + '0');
            buf[charPos++] = (char) (exponent % 10 + '0');
        } // if
    }
    return charPos;
}