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:edu.asu.ca.kaushik.algorithms.permvector.utils.CPHF.java

/**
 * A covering perfect hash family CPHF(n;k,v^t,t).
 * @param n//from www  .j  a  v  a  2 s.com
 * @param k
 * @param v
 * @param t
 */
public static int CPHF_LLL(int t, int k, int v) {
    double vTot = Math.pow(v, t);
    double nume = 1.0d;
    for (int i = 1; i < t; i++) {
        nume = nume * (vTot - Math.pow(v, i));
    }

    double dnom = Math.pow(vTot - 1.0d, t - 1);

    double q = 1.0d - nume / dnom;

    double d = CombinatoricsUtils.binomialCoefficientDouble(k, t)
            - CombinatoricsUtils.binomialCoefficientDouble(k - t, t);

    return (int) Math.ceil((1 + Math.log(d)) / (-Math.log(q)));
}

From source file:Main.java

/** Returns a human readable representation of a filesize given in bytes
 * @author Mr Ed - http://stackoverflow.com/a/5599842 
 * @param fileSizeInBytes the file size in bytes 
 * @return a human readable representation of the filesize using the following measures: Bytes, KiloBytes, MegaBytes,
 * GigaBytes, TeraBytes *//* w  w  w  . j  a v  a 2  s.c om*/
public static String getReadableFileSize(long fileSizeInBytes) {
    if (fileSizeInBytes <= 0) {
        return "0";
    }

    int digitGroups = (int) (Math.log10(fileSizeInBytes) / Math.log10(1024));

    return new DecimalFormat("#,##0.#").format(fileSizeInBytes / Math.pow(1024, digitGroups)) + " "
            + units[digitGroups];
}

From source file:Main.java

public static double calculateVariance(List<Double> list, double mean) {
    if (mean == Double.MAX_VALUE)
        return mean;
    if (list.size() == 1)
        return 0;
    double sum = 0;
    for (double num : list) {
        sum += Math.pow(num - mean, 2);
    }//from w  w  w. j a va 2s  .co  m
    return sum / (list.size() - 1);
}

From source file:Main.java

public static int extendDimension(int x) {
    if (x < 1)
        throw new IllegalArgumentException("x must be greater or equal 1");
    int nextExp = nextExp2(x);
    int nextPow = nextExp + 1;
    int extDim = (int) Math.round(Math.pow(2.0, (double) nextPow));
    return extDim;
}

From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils.java

/**
 * Converts a column label to a (0 based) column index.
 * <p>//from  w  w  w. j  a v  a2  s . co  m
 * Label must match the format [A-Z]+ for result to be valid.
 *
 * @param column
 *            the column label
 * @return the (0 based) column index
 */
public static int getColumnIndex(String column) {
    int result = -1;
    char a = 'A' - 1;
    char[] chars = column.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        int pos = (chars[i] - a);
        result += pos * Math.pow(26, chars.length - i - 1);
    }
    return result;
}

From source file:Main.java

/**
 * Removes NoData cells from the DEM by passing a window over each cell and estimating the value using inverse-distance weighting.   
 * @param array: array to remove NoData cells from 
 * @param noDataVal: NoData value to search for and remove from array.  Should be an odd number so that the window is of equal size on both sides.
 * @param windowSize: Size of the search window
 * @return DEM data//  ww  w .  java2 s  . co m
 */
private static float[][] removeDemNoData(float[][] array, float noDataVal, int windowSize) {
    int half = (windowSize - 1) / 2;
    float distance;
    float weight;
    float[][] arrayOut = array;
    boolean noDataCellsRemaining = true;
    while (noDataCellsRemaining == true) {
        noDataCellsRemaining = false;
        for (int r = 0; r < array.length; r++) {
            for (int c = 0; c < array[0].length; c++) {
                if (array[r][c] == noDataVal) {
                    float weightsum = 0;
                    float weightedvalsum = 0;
                    for (int x = 0 - half; x < 1 + half; x++) {
                        for (int y = 0 - half; y < 1 + half; y++) {
                            //skip the current cell
                            if (x == 0 && y == 0) {
                                continue;
                            }
                            //verify that the cell is in the DEM range
                            if (r + y >= array.length || r + y < 0 || c + x >= array[0].length || c + x < 0) {
                                continue;
                            }
                            //verify that the neighbor cell is not NoDATA, as this will break the IDW computation
                            if (array[r + y][c + x] != noDataVal) {
                                distance = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
                                weight = 1 / distance;
                                weightsum += weight;
                                weightedvalsum += array[r + y][c + x] * weight;
                                arrayOut[r][c] = weightedvalsum / weightsum;

                            }
                        }
                    }
                    if (arrayOut[r][c] == noDataVal) {
                        noDataCellsRemaining = true;
                    }
                }
            }
        }
    }
    return arrayOut;
}

From source file:blackscholes.EuropeanCall.java

public double ValuationMethod() {
    NormalDistribution N = new NormalDistribution();
    double _b = r - b;
    double d1 = (Math.log(S / X) + (b + 0.5 * Math.pow(sigma, 2)) * T) / (sigma * Math.sqrt(T));
    double d2 = d1 - sigma * Math.sqrt(T);

    double Nd1 = N.cumulativeProbability(d1);
    double Nd2 = N.cumulativeProbability(d2);
    return S * Nd1 - X * Nd2 * Math.exp((b - r) * T);
}

From source file:Main.java

/**
 * Truncate a double-precision floating point number to a specific number of significant digits
 *
 * @return The new truncated double number (make sure to catch it)
 *//*from   w w w. ja  va2s. com*/
private static double truncateDouble(double inputDouble, int numberSignificantDigits) {
    double returnDouble = inputDouble * Math.pow(10, numberSignificantDigits);
    returnDouble = Math.rint(returnDouble);
    return (returnDouble / Math.pow(10, numberSignificantDigits));
}

From source file:Main.java

/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.//w w w .j  a va2 s  .c o m
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.RIGHT:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1,
                    stopColors, null, Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}

From source file:Main.java

public static void RGBToXYZ(int r, int g, int b, double[] outXyz) {
    if (outXyz.length != 3) {
        throw new IllegalArgumentException("outXyz must have a length of 3.");
    }//from   ww  w .  java 2 s.  c o m

    double sr = r / 255.0;
    sr = sr < 0.04045 ? sr / 12.92 : Math.pow((sr + 0.055) / 1.055, 2.4);
    double sg = g / 255.0;
    sg = sg < 0.04045 ? sg / 12.92 : Math.pow((sg + 0.055) / 1.055, 2.4);
    double sb = b / 255.0;
    sb = sb < 0.04045 ? sb / 12.92 : Math.pow((sb + 0.055) / 1.055, 2.4);

    outXyz[0] = 100 * (sr * 0.4124 + sg * 0.3576 + sb * 0.1805);
    outXyz[1] = 100 * (sr * 0.2126 + sg * 0.7152 + sb * 0.0722);
    outXyz[2] = 100 * (sr * 0.0193 + sg * 0.1192 + sb * 0.9505);
}