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 getMaxZoomLevel(int imageWidth, int imageHeight) {
    int biggerSize = imageWidth > imageHeight ? imageWidth : imageHeight;

    if (biggerSize == 0) {
        return 0;
    }/*w ww .  j a  v  a  2 s  . c  om*/

    return (int) Math.ceil(Math.log((double) biggerSize) / Math.log(2.0));
}

From source file:Main.java

public static Bitmap divide(Bitmap bitmap1, Bitmap bitmap2) {
    double alpha = Double.MIN_VALUE;
    int width = bitmap1.getWidth();
    int height = bitmap1.getHeight();
    Bitmap grayBitmap1 = toGrayScale(bitmap1);
    Bitmap grayBitmap2 = toGrayScale(bitmap2);
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            int value1 = Color.blue(grayBitmap1.getPixel(x, y));
            int value2 = Color.blue(grayBitmap2.getPixel(x, y));
            //                int resultValue = (int) (Math.abs((Math.log((value1 + alpha)/(value2 + alpha))) * 1000));
            int resultValue = (int) ((Math.abs(Math.log((value1 + alpha) / (value2 + alpha)))) * 255);
            result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue));
        }//  w ww  .ja  v a  2 s .  c om
    //        grayBitmap1.recycle();
    //        grayBitmap2.recycle();
    return result;
}

From source file:Util.java

/**
 * Computes p(x;n,p) where x~B(n,p)/*from w  w  w.j  av a  2  s  . c  o m*/
 */
// Copied as the "classic" method from Catherine Loader.
//  Fast and Accurate Computation of Binomial Probabilities.
//   2001.  (This is not the fast and accurate version.)
public static double logBinom(int x, int n, double p) {
    return logFactorial(n) - logFactorial(x) - logFactorial(n - x) + (x * Math.log(p))
            + ((n - x) * Math.log(1 - p));
}

From source file:Main.java

/**
 * decode the image bitmap according to specified size
 * //  w ww.  j  ava2 s  .  co 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

/**
 * Makes an human-readable string with 2 decimals of a number of bytes.
 * For example, (1024 * 1024 * 12.5) would return 12.50 MB.
 * @param bytes The number of bytes/*w ww .j  a va2  s.com*/
 * @return The human-readable bytes
 */
public static String formatBytes(long bytes) {
    int exp = (int) (Math.log(bytes) / Math.log(1024));
    String[] prefixes = new String[] { "", "K", "M", "G", "T", "P", "E" };
    String prefix = prefixes[exp];
    return String.format("%.2f %sB", bytes / Math.pow(1024, exp), prefix);
}

From source file:Main.java

/**
 * Decode a file from the path and return a bitmap
 * @param uri//ww  w . j a  v a2  s  . c o  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:gedi.util.math.stat.distributions.LfcDistribution.java

public static double dlfc(double l, double a, double b, boolean log_p) {
    double r = (a * l + 1) * Math.log(2) - MathFunctions.lbeta(a, b) - (a + b) * Math.log(1 + Math.pow(2, l));
    if (!log_p)// ww w .  j a va 2s.  co  m
        r = Math.exp(r);
    return r;
}

From source file:Main.java

public static int getSampleSize(int size, float maxSize) {
    int scale = 1;
    if (size > maxSize)
        scale = 1 << (int) (Math.log(size / maxSize) / Math.log(2));
    System.out.println("inSampleSize=" + scale);
    return scale;
}

From source file:com.mycompany.semconsolewebapp.FFT.java

public static int nextPower2(int length) {
    if (length == 0) {
        return 0;
    } else {/* ww w  .j a v a2s . c  o m*/
        return 1 << (int) Math.ceil(Math.log(length) / Math.log(2));
    }
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static double acosh(final double x) {
    final double y = x * x - 1;
    Validate.isTrue(y >= 0, "|x|>=1.0 for real solution");
    return Math.log(x + Math.sqrt(x * x - 1));
}