List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:Main.java
static String formatDec(float val, int dec) { int factor = (int) Math.pow(10, dec); int front = (int) (val); int back = (int) Math.abs(val * (factor)) % factor; return front + "." + back; }
From source file:Main.java
/** * Get the distance between two points./*from w w w . j a va 2s. c o m*/ */ public static int getDistance(float x1, float y1, float x2, float y2) { return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); }
From source file:Main.java
public static float distance(float x1, float y1, float x2, float y2) { float d1 = x1 - x2; float d2 = y1 - y2; return (float) Math.sqrt((float) Math.pow(d1, 2) + Math.pow(d2, 2)); }
From source file:IntUtils.java
public static byte[] IntToBytes(int i) { int digits, hiLimit, digit; byte[] bArr;//from ww w. j av a 2 s.c o m digits = IntLen(i); bArr = new byte[digits]; hiLimit = (int) Math.pow(10, digits - 1); for (int j = 0; j < digits; j++) { digit = i / hiLimit; bArr[j] = (byte) (48 + digit); i -= (digit * hiLimit); hiLimit /= 10; } return bArr; }
From source file:geogebra.util.MyMath.java
/** * Cubic root//from w w w. j a v a 2 s . co m * @param a * @return cube root */ final public static double cbrt(double a) { if (a > 0.0) return Math.pow(a, ONE_THIRD); else return -Math.pow(-a, ONE_THIRD); }
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)// w w w . ja va 2 s . c o m r = Math.exp(r); return r; }
From source file:Main.java
public static Bitmap revitionImageSize(String path, int width, int height) throws IOException { BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path))); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w.j av a 2 s .co m*/ BitmapFactory.decodeStream(in, null, options); in.close(); int i = 0; Bitmap bitmap = null; while (true) { if ((options.outWidth >> i <= width) && (options.outHeight >> i <= height)) { in = new BufferedInputStream(new FileInputStream(new File(path))); options.inSampleSize = (int) Math.pow(2.0D, i); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeStream(in, null, options); break; } i += 1; } return bitmap; }
From source file:edu.csun.ecs.cs.multitouchj.ui.utility.PointUtility.java
public static float getDistance(Point pointA, Point pointB) { return (float) Math .sqrt(Math.pow((pointB.getX() - pointA.getX()), 2) + Math.pow((pointB.getY() - pointA.getY()), 2)); }
From source file:edu.msu.cme.rdp.graph.utils.BloomFilterStats.java
public static void printStats(BloomFilter filter, PrintStream out) { long n = filter.getUniqueKmers(); long m = (long) Math.pow(2, filter.getHashSizeLog2()); int k = filter.getHashCount(); //(1-e^(-k*((n+.5)/(m-1))))^k double falsePositiveRate = Math.pow((1 - Math.pow(Math.E, -k * ((n + .5) / (m - 1)))), k); out.println("Bloom filter created on: " + filter.getCreatedOn()); out.println("Serializable id: " + BloomFilter.serialVersionUID); out.println();/*from w ww . j av a 2 s . c o m*/ out.println("Bloom filter size log 2: " + filter.getHashSizeLog2()); out.println("Bloom filter size (bits) (m): " + m); out.println(); out.println("Number of bitsets: " + filter.getNumBitsets()); out.println("Bitset size (bits): " + filter.getBitsetSize()); out.println("Bitset size log2: " + filter.getBitsetSizeLog2()); out.println(); out.println("Number of hashes (k): " + filter.getHashCount()); out.println("Hash function name: " + filter.getHasherClassName()); out.println(); out.println("Bitset Mask: " + StringUtils.leftPad(Long.toBinaryString(filter.getBitsetMask()), 64, '0')); out.println("Hash mask: " + StringUtils.leftPad(Long.toBinaryString(filter.getHashMask()), 64, '0')); out.println(); out.println("Kmer length: " + filter.getKmerSize()); out.println(); out.println("Total kmers in bloom filter: " + filter.getTotalKmers()); out.println("Total strings inserted: " + filter.getTotalStrings()); out.println("Total unique kmers: " + filter.getUniqueKmers()); if (filter.getSingltonKmers() > -1) { out.println("Total mercy kmers if set: " + filter.getMercyKmers()); out.println("Total singleton kmers: " + filter.getSingltonKmers()); } out.println("Predicted false positive rate: " + falsePositiveRate); }
From source file:edu.gmu.csd.processor.DataProcessor.java
public static WinningResult calculateMeanStandardDeviation(String raffle) { String[] dataFieldsArr = null; if (StringUtils.isNotEmpty(raffle)) { dataFieldsArr = StringUtils.split(raffle, ","); }/*from www.j a va 2 s . c o m*/ WinningResult winningResult = null; if (null != dataFieldsArr) { double mean; double sum = 0; double squareSum = 0; double stndrdDeviation; // First for loop to calculate the mean. for (String meanData : dataFieldsArr) { sum = sum + Integer.parseInt(meanData); } mean = sum / dataFieldsArr.length; // Second for loop to calculate the standard deviation. for (String sdData : dataFieldsArr) { double square = Math.pow((Integer.parseInt(sdData) - mean), 2); squareSum = squareSum + square; } stndrdDeviation = Math.sqrt(squareSum / (dataFieldsArr.length - 1)); winningResult = new WinningResult(); winningResult.setMean(mean); winningResult.setStandardDeviation(stndrdDeviation); } return winningResult; }