Example usage for java.lang Math log

List of usage examples for java.lang Math log

Introduction

In this page you can find the example usage for java.lang Math log.

Prototype

@HotSpotIntrinsicCandidate
public static double log(double a) 

Source Link

Document

Returns the natural logarithm (base e) of a double value.

Usage

From source file:Main.java

public static int getFibonacciSeq(long f) {
    return (int) Math.floor(Math.log(f * sqrt(5) + 0.5) / Math.log(GOLDEN_RATIO));
}

From source file:Main.java

/**
 * Calculate the optimal number of hash functions for the bloom filter using
 * bloom filter size and no of elements inserted
 * //  w ww.jav a 2 s.c  om
 * @param bloomFilterSize
 *            Bloom Filter vector size
 * @param noOfElements
 *            Expected number of elements inserted to the filter
 * @return Optimal number of hash functions
 */

public static int optimalNoOfHash(int bloomFilterSize, long noOfElements) {
    return (int) Math.round(bloomFilterSize / noOfElements * Math.log(2));
}

From source file:Main.java

public static long[] getTileFromGeo(double lat, double lon, int zoom) {
    double rLon, rLat, a, k, z;
    rLon = lon * Math.PI / 180;//from   w ww  . j av  a2s  . c om
    rLat = lat * Math.PI / 180;
    a = 6378137;
    k = 0.0818191908426;
    z = Math.pow(Math.tan(Math.PI / 4 + rLat / 2) / (Math.tan(Math.PI / 4 + Math.asin(k * Math.sin(rLat)) / 2)),
            k);
    return new long[] { (int) (((20037508.342789 + a * rLon) * 53.5865938 / Math.pow(2, (23 - zoom))) / 256),
            (int) (((20037508.342789 - a * Math.log(z)) * 53.5865938 / Math.pow(2, (23 - zoom)))) / 256 };
}

From source file:Main.java

public static String calculateSize(String value) {

    long bytes = Long.parseLong(value);

    int unit = 1024;
    if (bytes < unit)
        return bytes + " B";
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = "KMGTPE".charAt(exp - 1) + "i";

    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre).replace(",", ".");

}

From source file:Util.java

public static double sigmod_rev(double sig) {
    return (double) Math.log(sig / (1 - sig));
}

From source file:controller.DistributionController.java

public static void logNormal(double mean, double stand, double size, double extra) {
    numerosGerados.clear();//from w w  w .j a  v a  2 s  . co m
    double mu = Math.log(mean * mean / Math.sqrt(mean * mean + stand * stand));
    double sigma = Math.sqrt(Math.log((mean * mean + stand * stand) / (mean * mean)));
    LogNormalDistribution lg = new LogNormalDistribution(mu, sigma);
    Double n;
    for (int i = 0; i < size; i++) {
        n = extra + lg.sample();
        numerosGerados.add(n);
    }
}

From source file:Main.java

public static double log(double value, double base) {
    return Math.log(value) / Math.log(base);
}

From source file:Main.java

public static float log(float a) {
    return (float) Math.log(a);
}

From source file:Main.java

public static double readHashTopValue(HashMap<String, Integer> scores, int k) {
    List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(scores.entrySet());
    int count = 0;
    int value = 0;
    double res = 0;
    for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); count < k && it.hasNext();) {
        Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next();
        value = (Integer) entry.getValue();
        res += (double) value * Math.log(2) / Math.log(count + 2);
        // res += (Integer) entry.getValue();
        count++;//from  w  w  w .j a v  a2 s.c o  m
    }
    return res;
}

From source file:Main.java

public static Bitmap Bytes2Bimap(byte[] bytes, int maxSize) {
    try {//from w  w  w.jav a 2s  .  co  m
        if (bytes == null) {
            return null;
        }

        if (bytes.length != 0) {
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opt);

            int scale = 1;

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

            BitmapFactory.Options newOpt = new BitmapFactory.Options();
            newOpt.inSampleSize = scale;

            return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, newOpt);
        } else {
            return null;
        }
    } catch (Exception ex) {
        return null;
    }
}