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

static public final float pow(float a, float b) {
    return (float) Math.pow(a, b);
}

From source file:Main.java

public static Bitmap decodeFileFromDrawable(int id, int maxSize, Context context) {
    Bitmap b = null;//from   w  w  w  .j av a 2  s.  co m
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        InputStream inputStream = context.getResources().openRawResource(id);
        BitmapFactory.decodeStream(inputStream, null, o);
        inputStream.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;
        inputStream = context.getResources().openRawResource(id);
        b = BitmapFactory.decodeStream(inputStream, null, o2);
        inputStream.close();
    } catch (IOException e) {
    }
    return b;
}

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

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

From source file:Main.java

/**
 * Convert RGB to XYZ/*w ww. ja v a  2  s .com*/
 *
 * @param R
 * @param G
 * @param B
 * @return XYZ in double array.
 */
public static double[] RGBtoXYZ(int R, int G, int B) {
    double[] result = new double[3];

    // convert 0..255 into 0..1
    double r = R / 255.0;
    double g = G / 255.0;
    double b = B / 255.0;

    // assume sRGB
    if (r <= 0.04045) {
        r = r / 12.92;
    } else {
        r = Math.pow(((r + 0.055) / 1.055), 2.4);
    }
    if (g <= 0.04045) {
        g = g / 12.92;
    } else {
        g = Math.pow(((g + 0.055) / 1.055), 2.4);
    }
    if (b <= 0.04045) {
        b = b / 12.92;
    } else {
        b = Math.pow(((b + 0.055) / 1.055), 2.4);
    }

    r *= 100.0;
    g *= 100.0;
    b *= 100.0;

    // [X Y Z] = [r g b][M]
    result[0] = (r * M[0][0]) + (g * M[0][1]) + (b * M[0][2]);
    result[1] = (r * M[1][0]) + (g * M[1][1]) + (b * M[1][2]);
    result[2] = (r * M[2][0]) + (g * M[2][1]) + (b * M[2][2]);

    return result;
}

From source file:Main.java

/**
 * Returns the euclidean distance between two LAB colors.
 *///www  . j  ava2 s  .c  om
public static double distanceEuclidean(double[] labX, double[] labY) {
    return Math.sqrt(
            Math.pow(labX[0] - labY[0], 2) + Math.pow(labX[1] - labY[1], 2) + Math.pow(labX[2] - labY[2], 2));
}

From source file:Main.java

public static float easeOut(float n) {
    return (float) (DOMAIN * Math.pow(n / DURATION, 0.48) + START);
}

From source file:Main.java

static double roundOff(double x, int position) {
    double a = x;
    double temp = Math.pow(10.0, position);
    a *= temp;//from www .  jav a 2  s.  co m
    a = Math.round(a);
    return (a / (double) temp);
}

From source file:Main.java

private static double getDistance(int color, int tempColor) {
    double red, green, blue;

    red = Math.pow(Color.red(tempColor) - Color.red(color), 2.0);
    green = Math.pow(Color.green(tempColor) - Color.green(color), 2.0);
    blue = Math.pow(Color.blue(tempColor) - Color.blue(color), 2.0);

    return Math.sqrt(blue + green + red);
}

From source file:Main.java

public static Float getFloatValue(byte[] value, int format, int position) {
    if (value == null || (format & 15) + position > value.length) {
        return null;
    }// w  ww  .j  a  v  a  2 s  . c om
    switch (format) {
    case FORMAT_SFLOAT /*50*/:
        int i = value[position + FIRST_BITMASK];
        return Float.valueOf(
                (float) (((double) signed((value[position] & 255) + (((i & 255) & 15) << FOURTH_BITMASK), 12))
                        * Math.pow(10.0d, (double) signed((i & 255) >> THIRD_BITMASK, THIRD_BITMASK))));
    case FORMAT_FLOAT /*52*/:
        int exponent = value[position + 3];
        int mantissa = value[position + SECOND_BITMASK];
        return Float.valueOf((float) (((double) signed(
                ((value[position] & 255) + ((value[position + FIRST_BITMASK] & 255) << FOURTH_BITMASK))
                        + ((mantissa & 255) << FIFTH_BITMASK),
                24)) * Math.pow(10.0d, (double) exponent)));
    default:
        return null;
    }
}

From source file:Main.java

/**
 * @see <a href="http://svn.xiph.org/trunk/vorbis/lib/sharedbook.c">_book_maptype1_quantvals</a>
 *//*from   www  .  ja  va  2 s .co  m*/
private static long mapType1QuantValues(long entries, long dimension) {
    return (long) Math.floor(Math.pow(entries, 1.d / dimension));
}