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

/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is twice the device screen diagonal for default implementation (extra quality to zoom image).
 * Size cannot exceed max texture size.//from  w  w  w. ja  v  a  2 s.c o m
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({ "SuspiciousNameCombination", "deprecation" })
public static int calculateMaxBitmapSize(@NonNull Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }

    int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

    Canvas canvas = new Canvas();
    return Math.min(screenDiagonal * 2,
            Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()));
}

From source file:Main.java

/**
 * assume one pix use 4 bytes.Bitmap.Config.ARGB_8888.
 *///from  w w  w . ja v  a2 s  . com
private final static int calculateInSampleSize(Options options, long reqMemorySize) {
    final int onePixBytes = 4;
    int reqPixs = (int) (reqMemorySize / onePixBytes);
    final int height = options.outHeight;
    final int width = options.outWidth;
    int orgPixs = height * width;
    int inSampleSize = 1;
    while (orgPixs / Math.pow(inSampleSize, 2) > reqPixs) {
        inSampleSize *= 2;

    }
    return inSampleSize;

}

From source file:Main.java

public static final double toFixed(final double d, final double precision) {
    final double pow = Math.pow(10, precision);
    return Math.round(d * pow) / pow;
}

From source file:Main.java

/**
 * Determine the size of screen for this device.
 *
 * @param context/*from w w w  .ja v a 2s .c  om*/
 * @return double
 * @deprecated
 */
@Deprecated
public static double tabletSize(Context context) {

    double size = 0;
    try {
        // Compute screen size
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        float screenWidth = dm.widthPixels / dm.xdpi;
        float screenHeight = dm.heightPixels / dm.ydpi;
        //noinspection SuspiciousNameCombination
        size = Math.sqrt(Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2));
    } catch (Throwable ignored) {

    }

    return size;

}

From source file:Main.java

/**
 * Makes an human-readable string with 2 decimals of a number of bytes.
 * For example, (1024 * 1024 * 12.5) would return 12.50 MB.
 * @param bytes The number of bytes/*from w  w  w  . ja  va 2  s.  co  m*/
 * @return The human-readable bytes
 */
public static String formatBytes(long bytes) {
    int exp = (int) (Math.log(bytes) / Math.log(1024));
    String[] prefixes = new String[] { "", "K", "M", "G", "T", "P", "E" };
    String prefix = prefixes[exp];
    return String.format("%.2f %sB", bytes / Math.pow(1024, exp), prefix);
}

From source file:Main.java

public static int itoa(int iSrc, byte[] buffer) {
    int positionalNumber = getPositionalNumber(iSrc);
    int length = positionalNumber;

    int i = 0;// w  w  w.  j a v  a  2 s. c om
    while (positionalNumber > 0) {
        int jesu = (int) Math.pow(10, positionalNumber - 1);
        int quotiont = iSrc / jesu;

        buffer[i] = (byte) (quotiont + '0');

        int remainder = iSrc % jesu;

        positionalNumber--;
        i++;
        iSrc = remainder;
    }
    return length;
}

From source file:Main.java

/**
 * Computes distance between points in any dimension.
 * /*  w w  w  . j a  v  a 2  s .com*/
 * @param p0 point 0
 * @param p1 point 1
 * 
 * @return distance between points
 */
private static Double distance(double[] p0, double[] p1) {
    // Must be of same dimension
    if (p0.length != p1.length)
        return null;

    // Calculate distance
    double val = 0;
    for (int n = 0; n < p0.length; n++)
        val += Math.pow(p1[n] - p0[n], 2);
    return Math.sqrt(val);
}

From source file:Main.java

/**
 * Returns the norm of the vector//from  w w w .jav  a 2 s  . co m
 *
 * @return the norm of the vector
 */
public static double norm(double[] array) {

    if (array != null) {
        int n = array.length;
        double sum = 0.0;

        for (int i = 0; i < n; i++) {
            sum += array[i] * array[i];
        }
        return Math.pow(sum, 0.5);
    } else
        return 0.0;
}

From source file:Main.java

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

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

From source file:edu.asu.ca.kaushik.algorithms.permvector.utils.SCPHF.java

public static int SCPHF_LLL(int t, int k, int v) {
    double covP = 1.0d;

    for (int i = 1; i < t; i++) {
        covP = covP * (1.0d - 1 / Math.pow(v, i));
    }/*from   w  ww.  j a v  a  2 s.  co  m*/

    double q = 1.0d - covP;

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

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