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

public static int nextPowerOfTwo(int n) {
    if (isPowerOfTwo(n)) {
        return n;
    }/*w ww .  j  ava2  s . c o m*/
    int i = 0;
    for (;;) {
        i++;
        if (Math.pow(2, i) >= n) {
            return (int) Math.pow(2, i);
        }
    }
}

From source file:Main.java

public static float easeInOut(float n) {
    double q = 0.48f - n / DURATION / 1.04f, Q = Math.sqrt(0.1734f + q * q), x = Q - q,
            X = Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1), y = -Q - q,
            Y = Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1), t = X + Y + 0.5f;
    return (float) (DOMAIN * ((1 - t) * 3 * t * t + t * t * t) + START);
}

From source file:Main.java

/**
 * //from  w w  w.  j a  va  2  s .c  o  m
 * @param file
 */
public static void decodeFile(File file) {
    Bitmap bitmap = null;

    try {
        // Decode image size
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;

        FileInputStream fileInputStream = new FileInputStream(file);
        BitmapFactory.decodeStream(fileInputStream, null, options);
        fileInputStream.close();

        int scale = 1;

        if (options.outHeight > 500 || options.outWidth > 500) {
            scale = (int) Math.pow(2, (int) Math.round(
                    Math.log(500 / (double) Math.max(options.outHeight, options.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options options2 = new BitmapFactory.Options();
        options2.inSampleSize = scale;

        fileInputStream = new FileInputStream(file);
        bitmap = BitmapFactory.decodeStream(fileInputStream, null, options2);
        fileInputStream.close();

        FileOutputStream output = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, output);

        output.flush();
        output.close();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:Main.java

private static double rgb_xyz(double r) {
    if ((r /= 255) <= 0.04045) {
        return (r / 12.92);
    } else {// w w  w .j  av  a2s  .com
        return (Math.pow((r + 0.055) / 1.055, 2.4));
    }
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static boolean compareFloat(float a, float b, int precision) {
    return Math.abs(a - b) <= Math.pow(10, -precision);
}

From source file:Main.java

public static double betai(final double a, final double b, final double x) {
    double bt = 0.0;
    if (x == 0.0 || x == 1.0) {
        bt = 0.0;/*from w w w .jav  a 2 s. co m*/
    } else if (x > 0.0 && x < 1.0) {
        bt = gamma(a + b) * Math.pow(x, a) * Math.pow(1.0 - x, b) / (gamma(a) * gamma(b));
    }
    double beta;
    if (x < (a + 1.0) / (a + b + 2.0)) {
        beta = bt * betacf(a, b, x) / a;
    } else {
        beta = 1.0 - bt * betacf(b, a, 1.0 - x) / b;
    }
    return beta;
}

From source file:Main.java

public static int getInSampleSize(double scale) {
    double log = Math.log(scale) / Math.log(2);
    double logCeil = Math.ceil(log);
    return ((int) Math.pow(2, logCeil) + 1);
}

From source file:Main.java

/**
 * @param number//from   w w  w . j a  va 2  s. c o  m
 * @param decimals
 * @return
 */
public static float roundDecimals(double number, int decimals) {
    double rounder = Math.pow(10, decimals);

    int ix = (int) (number * rounder);
    return (float) (ix / rounder);
}

From source file:Com.Operaciones.java

public static double Redondear(double NDecimal, int decimales) {
    return Math.round(NDecimal * Math.pow(10, decimales)) / Math.pow(10, decimales);
}

From source file:Main.java

/**
 * Given a number, round up to the nearest power of ten times 1, 2, or 5.
 * /* w w w .ja v a2s. c  o  m*/
 * @param val the number, it must be strictly positive
 */
private static double roundUp(final double val) {
    int exponent = (int) Math.floor(Math.log10(val));
    double rval = val * Math.pow(10, -exponent);
    if (rval > 5.0) {
        rval = 10.0;
    } else if (rval > 2.0) {
        rval = 5.0;
    } else if (rval > 1.0) {
        rval = 2.0;
    }
    rval *= Math.pow(10, exponent);
    return rval;
}