List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:org.wallerlab.yoink.adaptive.smooth.smoothfunction.BuloSmoothFunction.java
/** * this smooth function is used in difference-based adaptive solvation(DAS) * method. for details please see:/* w ww. j av a2s.com*/ * "Toward a practical method for adaptive QM/MM simulations." Journal of * Chemical Theory and Computation 5.9 (2009): 2212-2221. * * @param currentValue * , currentValue(variable) in smooth function * @param min * , minimum value in smooth function * @param max * , maximum value in smooth function * @return smooth factor */ public double evaluate(double currentValue, double min, double max) { double smoothFactor; if (currentValue > max) { smoothFactor = 1; } else if (currentValue < min) { smoothFactor = 0; } else { smoothFactor = Math.pow((currentValue - min), 2); smoothFactor = smoothFactor * (3 * max - min - 2 * currentValue); smoothFactor = smoothFactor / Math.pow((max - min), 3); } return smoothFactor; }
From source file:SpringCompactGrid.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*w ww. ja v a2s . c o m*/ private static void createAndShowGUI() { JPanel panel = new JPanel(new SpringLayout()); int rows = 10; int cols = 10; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int anInt = (int) Math.pow(r, c); JTextField textField = new JTextField(Integer.toString(anInt)); panel.add(textField); } } //Lay out the panel. SpringUtilities.makeCompactGrid(panel, //parent rows, cols, 3, 3, //initX, initY 3, 3); //xPad, yPad //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringCompactGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:PriorityCompete.java
public static double roundTo(double val, int places) { double factor = Math.pow(10, places); return ((int) ((val * factor) + 0.5)) / factor; }
From source file:net.bither.model.Depth.java
public static Depth formatJsonOfMarketDepth(MarketType marketType, JSONObject json) throws JSONException { Depth depth = new Depth(); double rate = ExchangeUtil.getRate(marketType); int bidMaxPrice = 0; int askMinPrice = Integer.MAX_VALUE; List<DateValueEntity> bidDateValueEntities = new ArrayList<DateValueEntity>(); List<DateValueEntity> askDateValueEntities = new ArrayList<DateValueEntity>(); double bidSumVolume = 0; int splitIndex = 0; if (!json.isNull(BIDS)) { JSONArray bidArray = json.getJSONArray(BIDS); for (int i = bidArray.length() - 1; i >= 0; i--) { JSONArray bid = bidArray.getJSONArray(i); int bidPrice = bid.getInt(0); double price = ((double) bidPrice) / 100 * rate; double volume = bid.getDouble(1) / Math.pow(10, 8); if (bidMaxPrice < bidPrice) { bidMaxPrice = bidPrice;/*from w w w . j a v a 2s. c om*/ } bidSumVolume = bidSumVolume + volume; DateValueEntity dateValueEntity = new DateValueEntity((float) bidSumVolume, StringUtil.formatDoubleToMoneyString(price), bidPrice); bidDateValueEntities.add(dateValueEntity); } splitIndex = bidArray.length(); } double askSumVolume = 0; if (!json.isNull(ASKS)) { JSONArray askArray = json.getJSONArray(ASKS); for (int i = 0; i < askArray.length(); i++) { JSONArray ask = askArray.getJSONArray(i); int askPrice = ask.getInt(0); double price = ((double) askPrice) / 100 * rate; double volume = ask.getDouble(1) / Math.pow(10, 8); askSumVolume = askSumVolume + volume; if (askPrice < askMinPrice) { askMinPrice = askPrice; } DateValueEntity dateValueEntity = new DateValueEntity((float) askSumVolume, StringUtil.formatDoubleToMoneyString(price), askPrice); askDateValueEntities.add(dateValueEntity); } } int mixPrice = (askMinPrice + bidMaxPrice) / 2; DateValueEntity zeroDateValue = new DateValueEntity(0, StringUtil.formatDoubleToMoneyString(((double) mixPrice) / 100 * rate), mixPrice); List<DateValueEntity> dateValueEntities = new ArrayList<DateValueEntity>(); dateValueEntities.addAll(bidDateValueEntities); dateValueEntities.add(zeroDateValue); dateValueEntities.addAll(askDateValueEntities); Collections.sort(dateValueEntities, new ComparatorDateValue()); depth.setMaxVolume(Math.max(askSumVolume, bidSumVolume)); depth.setDateValueEntities(dateValueEntities); depth.setSplitIndex(splitIndex); return depth; }
From source file:interpolation.Polyfit.java
public Polyfit(double[] x, double[] y, int degree) { this.degree = degree; Npoints = x.length;/* www . jav a 2s.c o m*/ // Vandermonde matrix double[][] vandermonde = new double[Npoints][degree + 1]; for (int i = 0; i < Npoints; i++) { for (int j = 0; j <= degree; j++) { vandermonde[i][j] = Math.pow(x[i], j); } } Matrix X = new Matrix(vandermonde); // create matrix from vector Matrix Y = new Matrix(y, Npoints); // find least squares solution QRDecomposition qr = new QRDecomposition(X); Coefficients = qr.solve(Y); // mean of y[] values double sum = 0.0; for (int i = 0; i < Npoints; i++) sum += y[i]; double mean = sum / Npoints; // total variation to be accounted for for (int i = 0; i < Npoints; i++) { double dev = y[i] - mean; SST += dev * dev; } // variation not accounted for Matrix residuals = X.times(Coefficients).minus(Y); SSE = residuals.norm2() * residuals.norm2(); }
From source file:bits.MultiSyncPatternMatcher.java
public MultiSyncPatternMatcher(int syncSize) { Validate.isTrue(syncSize < 64);/*from w ww .j av a 2s . c o m*/ //Setup a bit mask of all ones the length of the sync pattern mMask = (long) ((Math.pow(2, syncSize)) - 1); }
From source file:com.torchmind.authenticator.AbstractTokenGenerator.java
AbstractTokenGenerator(@NonNull Algorithm algorithm, int digits, @NonNull String issuer) { this.algorithm = algorithm; this.digits = digits; this.issuer = issuer; this.digitModulo = (int) Math.pow(10, digits); }
From source file:com.ery.estorm.zk.RetryCounter.java
/** * Sleep for a exponentially back off time * //from www .j ava2 s .c o m * @throws InterruptedException */ public void sleepUntilNextRetry() throws InterruptedException { int attempts = getAttemptTimes(); long sleepTime = (long) (retryIntervalMillis * Math.pow(2, attempts)); LOG.info("Sleeping " + sleepTime + "ms before retry #" + attempts + "..."); timeUnit.sleep(sleepTime); }
From source file:org.wallerlab.yoink.adaptive.smooth.smoothfunction.BrooksSmoothFunction.java
/** * this smooth function is used in hot-spot method. for details please see: * "A QM/MM simulation method applied to the solution of Li+ in liquid ammonia." * Chemical physics 211.1 (1996): 313-323. * /*from w w w. j av a 2s. c o m*/ * @param currentValue, currentValue(variable) in smooth function * @param min, minimum value in smooth function * @param max, maximum value in smooth function * @return smooth factor */ public double evaluate(double currentValue, double min, double max) { double smoothFactor; if (currentValue > max) { smoothFactor = 0; } else if (currentValue <= min) { smoothFactor = 1; } else { smoothFactor = Math.pow((Math.pow(max, 2) - Math.pow(currentValue, 2)), 2); smoothFactor = smoothFactor * (Math.pow(max, 2) + 2 * Math.pow(currentValue, 2) - 3 * Math.pow(min, 2)); smoothFactor = smoothFactor / Math.pow((max * max - min * min), 3); } return smoothFactor; }
From source file:eu.flatworld.worldexplorer.layer.nltl7.NLTL7HTTPProvider.java
@Override public Tile getTile(int id, int x, int y, int l) throws Exception { Tile tile = null;//from w w w. j av a 2 s .c o m tile = new NLTL7Tile(); tile.setX(x); tile.setY(y); tile.setGx(x); tile.setGy((int) Math.pow(2, l) * NLTL7Layer.SURFACE_HEIGHT - 1 - y); tile.setL(l); LogX.log(Level.FINEST, NAME + " queueing: " + tile); firePropertyChange(P_IDLE, true, false); queueTile(tile); return tile; }