List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:curveavg.QuinticFunction.java
public double value(double x) { return (a * Math.pow(x, 5) + b * Math.pow(x, 4) + c * Math.pow(x, 3) + d * Math.pow(x, 2) + e * x + f); }
From source file:Methods.CalculusNewtonRaphson.java
public static void newtonRaphson1(double xold, double decPoint) {//method used calculate root point acording the paramethers that enter the method and store the data in a global paramether linked list double xnew, fxold, fxnew, fdashxold, diff; int iteration = 0; xNewLinkedList.head = null;//Clearing the linked list before using it xLinkedList.head = null;/* w w w.j av a 2 s .co m*/ do { iteration += 1; fxold = xold - Math.pow(xold, 2.0); fdashxold = 1.0 - (2.0 * xold); xnew = xold - (fxold / fdashxold); fxnew = xnew - Math.pow(xnew, 2.0); System.out.println("Approx for iteration{}" + iteration + " is " + xnew); if (iteration == 1) {//Block used to insert data in the linked list xNewLinkedList.addFirst(xold, fxold, iteration); xLinkedList.addFirst(xnew, fxnew, iteration); } else { xNewLinkedList.addMid(xold, fxold, iteration, iteration - 1); xLinkedList.addMid(xnew, fxnew, iteration, iteration - 1); } diff = Math.abs(xnew - xold); xold = xnew; } while (diff > decPoint); xNewLinkedList.addMid(xnew, 0.0, iteration + 1, iteration);//Block used to insert data in the linked list xLinkedList.addMid(xnew, 0.0, iteration + 1, iteration); System.out.println("root to six decimal places is " + xnew); }
From source file:com.espertech.esper.support.util.DoubleValueAssertionUtil.java
public static boolean equals(double valueActual, double valueExpected, int precision) { if (precision < 1) { throw new IllegalArgumentException("Invalid precision value of " + precision + " supplied"); }/*from ww w . jav a2s .c om*/ if ((Double.valueOf(valueActual).isNaN()) && (Double.valueOf(valueExpected).isNaN())) { return true; } if (((Double.valueOf(valueActual).isNaN()) && (!Double.valueOf(valueExpected).isNaN())) || ((!Double.valueOf(valueActual).isNaN()) && (Double.valueOf(valueExpected).isNaN()))) { log.debug(".equals Compare failed, " + " valueActual=" + valueActual + " valueExpected=" + valueExpected); return false; } double factor = Math.pow(10, precision); double val1 = valueActual * factor; double val2 = valueExpected * factor; // Round to closest integer double d1 = Math.rint(val1); double d2 = Math.rint(val2); if (d1 != d2) { log.debug(".equals Compare failed, " + " valueActual=" + valueActual + " valueExpected=" + valueExpected + " precision=" + precision); return false; } return true; }
From source file:Main.java
/** * See: http://stackoverflow.com/questions/477572/android-strange * -out-of-memory-issue-while-loading-an-image * -to-a-bitmap-object/823966#823966 * Thanks to StackOverflow user named Fedor. *//*from w w w. j av a 2s . c o m*/ public static Bitmap decodeFile(File f, int size) { Bitmap b = null; try { 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 > size || o.outWidth > size) { scale = (int) Math.pow(2.0, (int) Math .round(Math.log(size / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inTempStorage = new byte[32 * 1024]; o2.inPurgeable = true; o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return b; }
From source file:Util.java
public static long[][] getBinomialDistribution(int min, int max, long total) { Random rand = new Random(System.currentTimeMillis()); int n = max - min; long[][] ret = new long[2][n + 1]; int mean = (n + 1) / 2; float p = 1;//from w ww . j a va 2 s. c o m if (n > 0) { p = (float) mean / (float) n; } long count = 0; for (int i = 0; i <= n; i++) { double p_i = combination(n, i) * Math.pow(p, i) * Math.pow((1 - p), (n - i)); long count_i = (long) (total * p_i); ret[0][i] = i + min; ret[1][i] = count_i; count += count_i; } while (count < total) { int i = rand.nextInt(n + 1); ret[1][i]++; count++; } return ret; }
From source file:com.opengamma.analytics.financial.interestrate.PeriodicInterestRate.java
public PeriodicInterestRate(final double rate, final int compoundingPeriodsPerYear) { super(rate);//from w ww . ja va2s. co m ArgumentChecker.notNegativeOrZero(compoundingPeriodsPerYear, "compounding periods per year"); _compoundingPeriodsPerYear = compoundingPeriodsPerYear; _oneYearValue = Math.pow(1 + rate / compoundingPeriodsPerYear, compoundingPeriodsPerYear); }
From source file:drpc.KMeansDrpcQuery.java
private static double computeRootMeanSquareDeviation(double[] v, double[] w) { double distance = 0; for (int i = 0; i < v.length && i < w.length; i++) { distance += Math.pow((v[i] - w[i]), 2); }/* w w w . j a v a2 s. c o m*/ return Math.sqrt(distance / (Math.min(v.length, w.length))); }
From source file:Main.java
/** * Fills the array with random floats. Values will be between min (inclusive) and * max (inclusive).// w ww.j ava 2s . c o m */ public static void genRandomFloats(long seed, float min, float max, float array[], boolean includeExtremes) { Random r = new Random(seed); int minExponent = Math.min(Math.getExponent(min), 0); int maxExponent = Math.max(Math.getExponent(max), 0); if (minExponent < -6 || maxExponent > 6) { // Use an exponential distribution int exponentDiff = maxExponent - minExponent; for (int i = 0; i < array.length; i++) { float mantissa = r.nextFloat(); int exponent = minExponent + r.nextInt(maxExponent - minExponent); int sign = (min >= 0) ? 1 : 1 - r.nextInt(2) * 2; // -1 or 1 float rand = sign * mantissa * (float) Math.pow(2.0, exponent); if (rand < min || rand > max) { continue; } array[i] = rand; } } else { // Use a linear distribution for (int i = 0; i < array.length; i++) { float rand = r.nextFloat(); array[i] = min + rand * (max - min); } } // Seed a few special numbers we want to be sure to test. for (int i = 0; i < sInterestingDoubles.length; i++) { float f = (float) sInterestingDoubles[i]; if (min <= f && f <= max) { array[r.nextInt(array.length)] = f; } } array[r.nextInt(array.length)] = min; array[r.nextInt(array.length)] = max; if (includeExtremes) { array[r.nextInt(array.length)] = Float.NaN; array[r.nextInt(array.length)] = Float.POSITIVE_INFINITY; array[r.nextInt(array.length)] = Float.NEGATIVE_INFINITY; array[r.nextInt(array.length)] = Float.MIN_VALUE; array[r.nextInt(array.length)] = Float.MIN_NORMAL; array[r.nextInt(array.length)] = Float.MAX_VALUE; array[r.nextInt(array.length)] = -Float.MIN_VALUE; array[r.nextInt(array.length)] = -Float.MIN_NORMAL; array[r.nextInt(array.length)] = -Float.MAX_VALUE; } }
From source file:Main.java
/** * Returns a List of Lists: all combinations of the elements of the given List. * @param maxCombinationSize combinations larger than this value are discarded * @param mandatoryItem an item that all returned combinations must contain, * or null to leave unspecified//from w w w . ja v a2 s . c om */ public static <E> List<List<E>> combinations(List<E> original, int maxCombinationSize, E mandatoryItem) { List<List<E>> combinations = new ArrayList<>(); //Combinations are given by the bits of each binary number from 1 to 2^N for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) { List<E> combination = new ArrayList<>(); for (int j = 0; j < original.size(); j++) { if ((i & (int) Math.pow(2, j)) > 0) { combination.add(original.get(j)); } } if (combination.size() > maxCombinationSize) { continue; } if ((mandatoryItem != null) && !combination.contains(mandatoryItem)) { continue; } combinations.add(combination); } return combinations; }
From source file:com.wegas.core.jcr.content.ContentConnector.java
/** * @param bytes//from w w w . j a va 2 s .co m * @return string representation */ public static String bytesToHumanReadable(Long bytes) { Integer unit = 1024; if (bytes < unit) { return bytes + "B"; } Integer exponent = (int) (Math.log(bytes) / Math.log(unit)); String prefix = ("KMGTPE").charAt(exponent - 1) + ""; return String.format("%.1f%sB", bytes / Math.pow(unit, exponent), prefix); }