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

private static double xyz_lab(double t) {
    if (t > t3) {
        return Math.pow(t, 1.0 / 3.0);
    } else {/*from w  w  w  .  j  a  va2s  .  c  o  m*/
        return t / t2 + t0;
    }
}

From source file:Main.java

/**
 * decode the image bitmap according to specified size
 * // w  w  w.ja va2  s. c  o  m
 * @param f
 * @param maxSize
 * @return
 */
public static Bitmap decodeFile(File f, int maxSize) {
    Bitmap b = null;
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

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

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (IOException e) {
    }
    return b;
}

From source file:Main.java

public static double getGeoDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
    double EARTH_RADIUS = 6378137;
    double radLat1 = rad(latitude1);
    double radLat2 = rad(latitude2);
    double a = radLat1 - radLat2;
    double b = rad(longitude1) - rad(longitude2);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;//from w  w  w .ja v a2 s .co m
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

/**
 * Decode a file from the path and return a bitmap
 * @param uri/*from  w w w .  j av a 2s.  co  m*/
 * @param context
 * @return
 */
public static Bitmap decodeFileFromPath(Uri uri, Context context) {

    InputStream in = null;
    try {
        in = context.getContentResolver().openInputStream(uri);

        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        BitmapFactory.decodeStream(in, null, o);
        in.close();

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

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        in = context.getContentResolver().openInputStream(uri);
        Bitmap b = BitmapFactory.decodeStream(in, null, o2);
        in.close();

        return b;

    } catch (FileNotFoundException e) {
        //e.printStackTrace();
    } catch (IOException e) {
        //e.printStackTrace();
    }
    return null;
}

From source file:Main.java

private static double getTwoComplement(double base, double maxNumberOfPlaces, double decimalValue) {
    return (Math.pow(base, maxNumberOfPlaces) - decimalValue);
}

From source file:Main.java

public static Bitmap getFocusedBitmap(Context context, Camera camera, Bitmap bmp, Rect box) {
    Point CamRes = getCameraResolution(context, camera);
    Point ScrRes = getScreenResolution(context);

    int SW = ScrRes.x;
    int SH = ScrRes.y;

    int RW = box.width();
    int RH = box.height();
    int RL = box.left;
    int RT = box.top;

    float RSW = (float) (RW * Math.pow(SW, -1));
    float RSH = (float) (RH * Math.pow(SH, -1));

    float RSL = (float) (RL * Math.pow(SW, -1));
    float RST = (float) (RT * Math.pow(SH, -1));

    int CW = CamRes.x;
    int CH = CamRes.y;

    if (CW > CH)
        bmp = rotateBitmap(bmp, 90);/*ww w  .ja v a  2s  .  c  o  m*/

    int BW = bmp.getWidth();
    int BH = bmp.getHeight();

    int RBL = (int) (RSL * BW);
    int RBT = (int) (RST * BH);

    int RBW = (int) (RSW * BW);
    int RBH = (int) (RSH * BH);

    Bitmap res = Bitmap.createBitmap(bmp, RBL, RBT, RBW, RBH);
    bmp.recycle();

    return res;
}

From source file:Main.java

public static double p_norm(double[] vals, int p) {

    double pnorm = 0.0;

    for (double d : vals) {
        pnorm += Math.pow(Math.abs(d), p);
    }//from w ww. ja v  a 2  s .c  o m

    return Math.pow(pnorm, (1.0d / (double) p));
}

From source file:Main.java

public static double sse(double[] a, double[] b) {
    double res = 0.0;
    int size = a.length;
    for (int i = 0; i < size; i++)
        res += Math.pow(a[i] - b[i], 2);
    return res;/*www. j a v a  2s. c  om*/
}

From source file:Main.java

public static String ReadableByteCount(long bytes) {
    if (bytes < 1024)
        return bytes + " B";
    int exp = (int) (Math.log(bytes) / Math.log(1024));
    String pre = String.valueOf("KMGTPE".charAt(exp - 1));
    return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre);
}

From source file:Main.java

public static float getMatrixScale(Matrix matrix) {
    synchronized (MATRIX_VALUES) {
        matrix.getValues(MATRIX_VALUES);
        final float scaleX = MATRIX_VALUES[Matrix.MSCALE_X];
        final float skewY = MATRIX_VALUES[Matrix.MSKEW_Y];
        //noinspection SuspiciousNameCombination
        return (float) Math.sqrt((float) Math.pow(scaleX, 2) + (float) Math.pow(skewY, 2));
    }/*from   w  w  w . j a v a 2s  .c  om*/
}