List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:juicebox.tools.utils.common.ArrayTools.java
/** * poisson.pdf(k) = exp(-mu) * mu**k / k! * * @param index//from w ww . j a v a 2s .c o m * @param width * @return */ public static double[] generatePoissonPMF(int index, int width) { double mu = Math.pow(2.0, (index + 1.0) / 3.0); double[] poissonPMF = new double[width]; PoissonDistributionImpl poissonDistribution = new PoissonDistributionImpl(mu); // use dynamic programming to grow poisson PMF for (int k = 0; k < width; k++) { poissonPMF[k] = poissonDistribution.probability(k); // the total is for scaling } return poissonPMF; }
From source file:Main.java
public static Bitmap decodeFile(File theFile, int IMAGE_MAX_SIZE) { Bitmap bmp = null;/*from w w w .j ava 2 s . c o m*/ try { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(theFile); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.round( Math.log(IMAGE_MAX_SIZE / (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(theFile); bmp = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return bmp; }
From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java
public static Bitmap loadPrescaledBitmap(String filename) throws IOException { // Facebook image size final int IMAGE_MAX_SIZE = 630; File file = null;//from w ww . j av a 2 s .c o m FileInputStream fis; BitmapFactory.Options opts; int resizeScale; Bitmap bmp; file = new File(filename); // This bit determines only the width/height of the bitmap without loading the contents opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; fis = new FileInputStream(file); BitmapFactory.decodeStream(fis, null, opts); fis.close(); // Find the correct scale value. It should be a power of 2 resizeScale = 1; if (opts.outHeight > IMAGE_MAX_SIZE || opts.outWidth > IMAGE_MAX_SIZE) { resizeScale = (int) Math.pow(2, (int) Math.round( Math.log(IMAGE_MAX_SIZE / (double) Math.max(opts.outHeight, opts.outWidth)) / Math.log(0.5))); } // Load pre-scaled bitmap opts = new BitmapFactory.Options(); opts.inSampleSize = resizeScale; fis = new FileInputStream(file); bmp = BitmapFactory.decodeStream(fis, null, opts); fis.close(); return bmp; }
From source file:com.mycompany.mavenproject1.Ex1.java
private int countOnes(Integer t) { int result = 0; for (int interation = 0; t / Math.pow(interation, 10) > 0; interation++) { result = (int) (result + t % Math.pow(interation, 10)); }/* w w w . jav a2 s .c o m*/ return result; }
From source file:com.thetechwarriors.cidrutils.Subnet.java
/** * Gets the maximum number of IP address in the current subnet. For example, * if current subnet is 192.168.1.0/24, then the max is 256. *//*from www.j av a2 s.co m*/ public long getMaxIpAddresses() { return (long) Math.pow(2, 32 - maskSize); }
From source file:com.jennifer.ui.util.MathUtil.java
private static double niceNum(double range, boolean round) { double exponent = Math.floor(Math.log10(range)); double fraction = range / Math.pow(10, exponent); double nickFraction; if (round) {/* w ww. j av a2s. c o m*/ if (fraction < 1.5) nickFraction = 1; else if (fraction < 3) nickFraction = 2; else if (fraction < 7) nickFraction = 5; else nickFraction = 10; } else { if (fraction <= 1) nickFraction = 1; else if (fraction <= 2) nickFraction = 2; else if (fraction <= 5) nickFraction = 5; else nickFraction = 10; } return nickFraction * Math.pow(10, exponent); }
From source file:FileUtils.java
public static float Round(float value, int numberOfPlaces) { float p = (float) Math.pow(10, numberOfPlaces); value = value * p;// ww w . j a va2 s . co m float tmp = Math.round(value); return (float) tmp / p; }
From source file:edu.uniandes.ecos.ase.calculo.CalculoSimpsonRule.java
@Override public double coeficienteDos(double coeficienteUno, double dof) { double coeficienteDos = 0; try {/*from w ww. j a v a 2 s.c om*/ coeficienteDos = Math.pow(coeficienteUno, (-(dof + 1) / 2)); } catch (Exception e) { System.out.println("Error calculando el coeficiente 2: " + e.getMessage()); } return coeficienteDos; }
From source file:me.datamining.bandwidth.SlivermanRule.java
public double bandWidth(double variance, int dimensions, long number) { return 1.06 * Math.pow(variance * number, -1.0 / 5.0); }
From source file:Main.java
/** * Creates an approximated cubic gradient using a multi-stop linear gradient. See * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more * details./*ww w . j a v a 2 s. c o m*/ */ public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) { numStops = Math.max(numStops, 2); PaintDrawable paintDrawable = new PaintDrawable(); paintDrawable.setShape(new RectShape()); final int[] stopColors = new int[numStops]; int red = Color.red(baseColor); int green = Color.green(baseColor); int blue = Color.blue(baseColor); int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { float x = i * 1f / (numStops - 1); float opacity = (float) Math.max(0, Math.min(1, Math.pow(x, 3))); stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue); } final float x0, x1, y0, y1; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: x0 = 1; x1 = 0; break; case Gravity.RIGHT: x0 = 0; x1 = 1; break; default: x0 = 0; x1 = 0; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: y0 = 1; y1 = 0; break; case Gravity.BOTTOM: y0 = 0; y1 = 1; break; default: y0 = 0; y1 = 0; break; } paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP); return linearGradient; } }); return paintDrawable; }