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:Main.java

/**
 * Calculates the luminance value of a given {@code int} representation of {@link Color}.
 * <p>//from   w  w w  .  j  a v  a 2  s.  c o m
 * Derived from formula at http://gmazzocato.altervista.org/colorwheel/algo.php
 *
 * @param color The {@link Color} to evaluate
 * @return the luminance value of the given color
 */
public static double calculateLuminance(int color) {
    final double[] sRGB = new double[3];
    sRGB[0] = Color.red(color) / 255.0d;
    sRGB[1] = Color.green(color) / 255.0d;
    sRGB[2] = Color.blue(color) / 255.0d;

    final double[] lumRGB = new double[3];
    for (int i = 0; i < sRGB.length; ++i) {
        lumRGB[i] = (sRGB[i] <= 0.03928d) ? sRGB[i] / 12.92d : Math.pow(((sRGB[i] + 0.055d) / 1.055d), 2.4d);
    }

    return 0.2126d * lumRGB[0] + 0.7152d * lumRGB[1] + 0.0722d * lumRGB[2];
}

From source file:PressureConverter.java

/**
 * Converts altitude in meters to pressure in msw
 * /* www  . j a  v a  2  s .  c  o  m*/
 * @return Pressure in msw or 0.0 if out of bounds.
 * @param altitude
 *            Altitude in meters
 */
public static double altitudeToPressure(double altitude) {
    if (altitude == 0.0)
        return 10.0;
    else if (altitude > 0.0)
        return Math.pow(((44330.8 - altitude) / 4946.54), 5.25588) / 10131.0;
    else
        return 0.0;
}

From source file:Main.java

public static double student_tDen(final double v, final double t) {
    return student_c(v) * Math.pow(1.0 + t * t / v, -0.5 * (v + 1.0));
}

From source file:Main.java

public static float computeCurvatureM2003(float x0, float y0, float x1, float y1, float x2, float y2) {

    double kappa = 0.0D;

    float a1 = (x2 - x0) / 2;
    float a2 = (x2 + x0) / 2 - x1;
    float b1 = (y2 - y0) / 2;
    float b2 = (y2 + y0) / 2 - y1;

    // float alpha = 0.0F;
    // alpha = (a1*b2 - a2*b1);
    // float beta  = 0.0F;
    // beta = a1*a1 + b1*b1;
    // float delta = 0.0F;
    // delta = (float) Math.pow((a1*a1 + b1*b1), 1.5);

    kappa = 2 * (a1 * b2 - a2 * b1) / Math.pow((a1 * a1 + b1 * b1), 1.5);
    return (float) kappa;
}

From source file:Main.java

/** Calculates the best tick spacing for the rounded minimal and maximal
 * values./*from   www  .  ja va 2 s.  c o m*/
 * @param min the rounded minimal value
 * @param max the rounded maximal value
 * @return the spacing of ticks on the x-axis.
 */
public static double calculateTickSpacing(double min, double max) {
    double spacing = 1.0;

    double diff = max - min;

    int exp = exp(diff);

    exp--;

    spacing = 1.0 * Math.pow(10.0, (double) exp);

    // Currently, only every second tick gets a label, so 20 - 40 ticks are fine. 
    // This should be reduced in a loop probably.
    if ((diff / spacing) < 20)
        return 0.5 * spacing;
    else if ((diff / spacing) > 40)
        return 2 * spacing;
    else
        return spacing;
}

From source file:Main.java

public static double gamma(double x) {
    double g = 1.0;
    double f;/*from  ww w. j  a  va  2  s  .co m*/
    if (x > 0.0) {
        while (x < 3.0) {
            g *= x;
            ++x;
        }
        f = (1.0 - 2.0 / (7.0 * Math.pow(x, 2.0)) * (1.0 - 2.0 / (3.0 * Math.pow(x, 2.0))))
                / (30.0 * Math.pow(x, 2.0));
        f = (1.0 - f) / (12.0 * x) + x * (Math.log(x) - 1.0);
        f = Math.exp(f) / g * Math.pow(6.283185307179586 / x, 0.5);
    } else {
        f = Double.POSITIVE_INFINITY;
    }
    return f;
}

From source file:Main.java

private void sizeToZoom() {
    double factor = Math.pow(ZOOM_AMOUNT, zoom);
    setSize((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor));
}

From source file:de.tynne.benchmarksuite.Main.java

private static double standardDeviationOf(DoubleStream doubleStream, double average) {
    double sum = doubleStream.map(x -> Math.pow(x - average, 2.)).average().getAsDouble();
    return Math.sqrt(sum);
}

From source file:drpc.KMeansDrpcQuery.java

private static double computeRootMeanSquare(double[] v) {
    double distance = 0;
    for (double aV : v) {
        distance += Math.pow((aV), 2);
    }/*from w  ww  .  ja v a 2s.  c o  m*/
    return Math.sqrt(distance / v.length);
}

From source file:Util.java

/**
 * generates n logarithmically-spaced points between d1 and d2 using the
 * provided base.//  w w w . j a  v a  2s  . co m
 * 
 * @param d1 The min value
 * @param d2 The max value
 * @param n The number of points to generated
 * @param base the logarithmic base to use
 * @return an array of lineraly space points.
 */
public static strictfp double[] logspace(double d1, double d2, int n, double base) {
    double[] y = new double[n];
    double[] p = linspace(d1, d2, n);
    for (int i = 0; i < y.length - 1; i++) {
        y[i] = Math.pow(base, p[i]);
    }
    y[y.length - 1] = Math.pow(base, d2);
    return y;
}