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 transponderAsParam(final int code) {
    int param = 0;
    int divisor = 1;
    for (int i = 0; i < 4; i++) {
        // pick off the digit, then re-interpret as hex
        final int digit = (code / divisor) % 10;
        param += digit * Math.pow(16, i);

        divisor *= 10;//  w w w  .  ja v  a2  s.  c  o m
    }

    return param;
}

From source file:Main.java

public static List<String> calculateResolutions(double dpi, double screenSize, boolean standard) {
    List<String> ret = new ArrayList<>();
    double bothSquaredSum = Math.pow(dpi * screenSize, 2);
    for (int i = 0; i < 10000; i++) {
        double other = Math.sqrt(bothSquaredSum - Math.pow(i, 2));
        double higher = Math.max(i, other), lower = Math.min(i, other);
        if (Double.isNaN(lower)) {
            continue;
        }/*  w  w  w. j a va 2s . c om*/
        if (standard) {
            double ratio = higher / lower;
            if (ratio == 4.0 / 3.0 || ratio == 16.0 / 9.0 || ratio == 16.0 / 10.0) {
                ret.add(String.format("%.0fx%.0f", higher, lower));
            }
        } else {
            ret.add(String.format("%.0fx%.0f", higher, lower));
        }
    }
    return ret;
}

From source file:Main.java

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

From source file:Main.java

private static <T extends Enum<T>> EnumSet bitwiseToEnumSet(Class<T> classType, int bitwise) {
    EnumSet<T> enumSet = EnumSet.noneOf(classType);
    for (T enumValue : EnumSet.allOf(classType)) {
        if ((bitwise & (int) Math.pow(2, enumValue.ordinal())) == (int) Math.pow(2, enumValue.ordinal()))
            enumSet.add(enumValue);//from   www .  j  ava 2  s. co m
    }
    return enumSet;
}

From source file:Main.java

public static double getScreenPhysicalSize(Context ctx) {
    DisplayMetrics dm = getDisplayMetrics(ctx);
    double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
    return diagonalPixels / (160 * dm.density);
}

From source file:Main.java

public static synchronized int edfHeaderBytesToInt(byte[] a) {
    int value = 0;
    int notspacecount = 0;
    for (int i = a.length - 1; i >= 0; i--) {
        if ((a[i] != 32) && (a[i] > 45)) {
            value = (int) (value + (a[i] - 48) * Math.pow(10, notspacecount));
            notspacecount++;// w  w  w . java2  s  . c o  m
        } else if (a[i] == 45) {
            value = value * -1;
        }
    }
    return value;
}

From source file:Main.java

/**
 * Get the display size in inches.//from  w  w  w  . j  ava2  s.co m
 * @return the value in inches
 */
public static double getDisplaySizeInches(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();

    double x = Math.pow((double) dm.widthPixels / (double) dm.densityDpi, 2);
    double y = Math.pow((double) dm.heightPixels / (double) dm.densityDpi, 2);

    return Math.sqrt(x + y);
}

From source file:Main.java

public static double pointDistance(PointF a, Point b) {
    return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}

From source file:Main.java

public static String getMatchingThresholdToString(int value) {
    double p = -value / 12.0;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(Math.max(0, (int) Math.ceil(-p) - 2));
    nf.setMinimumIntegerDigits(1);//  ww  w  .  j  a va 2 s  .  c o m
    return nf.format(Math.pow(10, p));
}

From source file:Main.java

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