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:com.opengamma.analytics.math.statistics.descriptive.GeometricMeanCalculator.java

/**
 * @param x The array of data, not null or empty
 * @return The geometric mean/*from   w w w . jav a 2 s .com*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 0, "x cannot be empty");
    final int n = x.length;
    double mult = x[0];
    for (int i = 1; i < n; i++) {
        mult *= x[i];
    }
    return Math.pow(mult, 1. / n);
}

From source file:Main.java

/**
 * Returns the closest power-of-two number less than or equal to x.
 * /* www.j  a va2s .c  om*/
 * @param x
 * @return the closest power-of-two number less then or equal to x
 */
public static int prevPow2(int x) {
    if (x < 1)
        throw new IllegalArgumentException("x must be greater or equal 1");
    return (int) Math.pow(2, Math.floor(Math.log(x) / Math.log(2)));
}

From source file:edu.uniandes.ecos.ase.calculo.CalculoSimpsonRule.java

@Override
public double coeficienteUno(double xi, double dof) {
    double coeficienteUno = 0;
    try {//www.  ja  v  a2s  .  c  o m
        coeficienteUno = 1 + ((Math.pow(xi, 2)) / dof);
    } catch (Exception e) {
        System.out.println("Error calculando el coeficiente 1: " + e.getMessage());
    }
    return coeficienteUno;
}

From source file:com.opengamma.analytics.math.interpolation.ExponentialInterpolator1D.java

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    final Double x1 = data.getLowerBoundKey(value);
    final Double y1 = data.get(x1);
    if (data.getLowerBoundIndex(value) == data.size() - 1) {
        return y1;
    }//from   w w  w  .j a  va  2  s.co  m
    final Double x2 = data.higherKey(x1);
    final Double y2 = data.get(x2);
    final double xDiff = x2 - x1;
    return Math.pow(y1, value * (x2 - value) / xDiff / x1) * Math.pow(y2, value * (value - x1) / xDiff / x2);
}

From source file:com.opengamma.strata.math.impl.function.RealPolynomialFunction1DTest.java

@Test
public void testEvaluate() {
    final double x = RANDOM.nextDouble();
    assertEquals(C[3] * Math.pow(x, 3) + C[2] * Math.pow(x, 2) + C[1] * x + C[0], F.applyAsDouble(x), EPS);
}

From source file:Main.java

public static void LABToXYZ(final double l, final double a, final double b, double[] outXyz) {
    final double fy = (l + 16) / 116;
    final double fx = a / 500 + fy;
    final double fz = fy - b / 200;

    double tmp = Math.pow(fx, 3);
    final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA;
    final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA;

    tmp = Math.pow(fz, 3);//from   w w  w  . ja v  a  2 s. c  o  m
    final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA;

    outXyz[0] = xr * XYZ_WHITE_REFERENCE_X;
    outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y;
    outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z;
}

From source file:dsp.unige.figures.ChannelHelper.java

/**
 * Returns hartley-Shannon capacity in bps, given Bandwidth (in Hz) and
 * Signal to Noise Ratio.// w w w .  jav a  2 s . c  o m
 * 
 * @param B the channel's bandwidth
 * @param s  Signal level in dB
 * @param n  Noise level in dB
 * @return Shannon max. theoretical information rate in bps.
 */
static public double getHSCapacity(int B, double s, double n) {
    System.out.println("ChannelHelper.getHSCapacity() B=" + B + " kHz");
    return B * Math.log(1 + Math.pow(10, (s - n) / 10)) / Math.log(2);
}

From source file:Main.java

@Override
public Object getValueAt(int row, int col) {
    return Math.pow(row, col + 1);
}

From source file:com.pinterest.secor.parser.TimestampedMessageParser.java

protected static long toMillis(final long timestamp) {
    final long nanosecondDivider = (long) Math.pow(10, 9 + 9);
    final long millisecondDivider = (long) Math.pow(10, 9 + 3);
    long timestampMillis;
    if (timestamp / nanosecondDivider > 0L) {
        timestampMillis = timestamp / (long) Math.pow(10, 6);
    } else if (timestamp / millisecondDivider > 0L) {
        timestampMillis = timestamp;//from www. jav  a  2 s  .co m
    } else { // assume seconds
        timestampMillis = timestamp * 1000L;
    }
    return timestampMillis;
}

From source file:edu.scripps.fl.curves.plot.GCurvePlot.java

protected static XYLine sampleFunctionToLine(Curve curve, FitFunction f, double start, double end,
        int samples) {
    double yValues[] = new double[samples];
    double xValues[] = new double[samples];

    double step = (end - start) / (double) (samples - 1);
    for (int i = 0; i < samples; i++) {
        double x = start + step * (double) i;
        xValues[i] = x;// www  .  jav  a  2  s  .com
        double y = f.getResponse(curve, Math.pow(10, x));
        yValues[i] = y;
    }

    Data xData = DataUtil.scaleWithinRange(NumberUtils.min(xValues), NumberUtils.max(xValues), xValues);
    Data yData = DataUtil.scaleWithinRange(NumberUtils.min(yValues), NumberUtils.max(yValues), yValues);
    return Plots.newXYLine(xData, yData, Color.GREEN, "");
}