List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.vyhnanovska.AutomatonLayoutTransformer.java
private Dimension computeGridDimension(final int minGridSize) { final Dimension dimension = new Dimension(); if (minGridSize < (minXsize * minYsize)) { dimension.setSize(minXsize, minXsize); } else {//from w ww . ja va 2s .c o m dimension.width = (int) Math.round(Math.sqrt(minGridSize * minYsize / minXsize)); dimension.height = (int) Math.floor(minGridSize / dimension.width) + 1; } return dimension; }
From source file:com.its.web.services.LicensesService.java
private String generateFiveCart() { String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; // Tu supprimes les lettres dont tu ne veux pas String pass = ""; for (int x = 0; x < 5; x++) { int i = (int) Math.floor(Math.random() * 62); pass += chars.charAt(i);/*from w ww .j av a2 s. co m*/ } return pass; }
From source file:org.ect.reo.simulation.simulator.Statistic.java
private int getBatchNrTime(double time) { // return the batch number for this time, it will return -1 if the batch number is not valid (less than 0 or greater than numOfBatches - 1) int result = (int) Math.floor(((time - sim.getWarmUpInterval()) / sim.getBatchLengthTime())); return ((result >= 0) && (result < numOfBatches)) ? result : -1; }
From source file:com.alvermont.terraj.stargen.util.NonRandomRandom.java
/** * Returns the next pseudorandom, uniformly distributed * <code>double</code> value between <code>0.0</code> and * <code>1.0</code> from this random number generator's sequence. <p> * The general contract of <tt>nextDouble</tt> is that one * <tt>double</tt> value, chosen (approximately) uniformly from the * range <tt>0.0d</tt> (inclusive) to <tt>1.0d</tt> (exclusive), is * pseudorandomly generated and returned. All * 2<font size="-1"><sup>53</sup></font> possible <tt>float</tt> * values of the form <i>m x </i>2<font size="-1"><sup>-53</sup> * </font>, where <i>m</i> is a positive integer less than * 2<font size="-1"><sup>53</sup></font>, are produced with * (approximately) equal probability. The method <tt>nextDouble</tt> is * implemented by class <tt>Random</tt> as follows: * <blockquote><pre>// www. java 2 s . com * public double nextDouble() { * return (((long)next(26) << 27) + next(27)) * / (double)(1L << 53); * }</pre></blockquote><p> * The hedge "approximately" is used in the foregoing description only * because the <tt>next</tt> method is only approximately an unbiased * source of independently chosen bits. If it were a perfect source or * randomly chosen bits, then the algorithm shown would choose * <tt>double</tt> values from the stated range with perfect uniformity. * <p>[In early versions of Java, the result was incorrectly calculated as: * <blockquote><pre> * return (((long)next(27) << 27) + next(27)) * / (double)(1L << 54);</pre></blockquote> * This might seem to be equivalent, if not better, but in fact it * introduced a large nonuniformity because of the bias in the rounding * of floating-point numbers: it was three times as likely that the * low-order bit of the significand would be 0 than that it would be * 1! This nonuniformity probably doesn't matter much in practice, but * we strive for perfection.] * * @return the next pseudorandom, uniformly distributed * <code>double</code> value between <code>0.0</code> and * <code>1.0</code> from this random number generator's sequence. */ public double nextDouble() { final double value = this.myDoubleValue; ++callCount; this.myDoubleValue += this.myIncrementValue; if (this.myDoubleValue > 1.0) { this.myDoubleValue = this.myDoubleValue - Math.floor(this.myDoubleValue); } return value; }
From source file:it.unimi.dsi.sux4j.mph.PaCoTrieDistributorMonotoneMinimalPerfectHashFunction.java
/** Creates a new PaCo-trie-based monotone minimal perfect hash function using the given * elements and transformation strategy. * //from w w w . ja v a 2s. co m * @param elements the elements among which the trie must be able to rank. * @param transform a transformation strategy that must turn the elements in <code>elements</code> into a list of * distinct, prefix-free, lexicographically increasing (in iteration order) bit vectors. */ public PaCoTrieDistributorMonotoneMinimalPerfectHashFunction(final Iterable<? extends T> elements, final TransformationStrategy<? super T> transform) throws IOException { this.transform = transform; defRetValue = -1; // For the very few cases in which we can decide long maxLength = 0; long totalLength = 0; BitVector bv; final RandomGenerator random = new XorShift1024StarRandomGenerator(); ProgressLogger pl = new ProgressLogger(LOGGER); pl.displayLocalSpeed = true; pl.displayFreeMemory = true; pl.itemsName = "keys"; pl.start("Creating chunked hash store..."); final ChunkedHashStore<BitVector> chunkedHashStore = new ChunkedHashStore<BitVector>( TransformationStrategies.identity()); chunkedHashStore.reset(random.nextLong()); for (T s : elements) { bv = transform.toBitVector(s); chunkedHashStore.add(bv); maxLength = Math.max(maxLength, bv.length()); totalLength += bv.length(); pl.lightUpdate(); } pl.done(); LOGGER.debug("Maximum length: " + maxLength); LOGGER.debug("Average length: " + totalLength / (double) chunkedHashStore.size()); size = chunkedHashStore.size(); if (size == 0) { bucketSize = log2BucketSize = 0; distributor = null; offset = null; chunkedHashStore.close(); return; } final long averageLength = (totalLength + size - 1) / size; int t = Fast.mostSignificantBit( (int) Math.floor(averageLength - Math.log(size) - Math.log(averageLength - Math.log(size)) - 1)); final int firstbucketSize = 1 << t; LOGGER.debug("First bucket size estimate: " + firstbucketSize); final Iterable<BitVector> bitVectors = TransformationStrategies.wrap(elements, transform); LOGGER.info("Creating distributor..."); PaCoTrieDistributor<BitVector> firstDistributor = new PaCoTrieDistributor<BitVector>(bitVectors, t, TransformationStrategies.identity()); if (firstDistributor.numBits() == 0 || firstbucketSize >= size) log2BucketSize = t; else { // Reassign bucket size based on empirical estimation log2BucketSize = t - Fast.mostSignificantBit((int) Math.ceil(size / (firstDistributor.numBits() * Math.log(2)))); } bucketSize = 1 << log2BucketSize; LOGGER.debug("Second bucket size estimate: " + bucketSize); if (firstbucketSize == bucketSize) distributor = firstDistributor; else { firstDistributor = null; distributor = new PaCoTrieDistributor<BitVector>(bitVectors, log2BucketSize, TransformationStrategies.identity()); } LOGGER.debug("Bucket size: " + bucketSize); final int bucketSizeMask = bucketSize - 1; LOGGER.info("Generating offset function..."); offset = new GOV3Function.Builder<BitVector>().keys(bitVectors) .transform(TransformationStrategies.identity()).store(chunkedHashStore) .values(new AbstractLongBigList() { public long getLong(long index) { return index & bucketSizeMask; } public long size64() { return size; } }, log2BucketSize).indirect().build(); chunkedHashStore.close(); LOGGER.debug("Forecast distributor bit cost: " + (size / bucketSize) * (maxLength + log2BucketSize - Math.log(size))); LOGGER.debug("Actual distributor bit cost: " + distributor.numBits()); LOGGER.debug("Forecast bit cost per element: " + (GOV3Function.C + Fast.log2(Math.E) - Fast.log2(Fast.log2(Math.E)) + Fast.log2(maxLength - Fast.log2(size)))); LOGGER.info("Actual bit cost per element: " + (double) numBits() / size); }
From source file:de.cosmocode.solr.SolrJServerTest.java
/** * <p> Tests adding a solr document and reading it with SolrJ afterwards. * </p>/*from w ww . j av a 2s . co m*/ * <p> After the test has run it deletes the created document * to provide a clean solr instance for the next test. * </p> * * @throws SolrServerException if some exception occurred in the solr server * @throws IOException if some low-level exception occurred (should not happen) */ @Test public void addAndQuery() throws SolrServerException, IOException { final String newId = "new_element_id_" + Math.floor(Math.random() * 10000); try { // add document final SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", newId); doc.addField("dynamic_t", "Blubbs, ein Text ... {look here}"); doc.addField("other_id_s", "12345"); server.add(doc); server.commit(); // read document final SolrJQuery query = SolrQueryFactory.createSolrJQuery(); query.addField("dynamic_t", "here}", SolrQuery.MOD_TEXT); query.addField("other_id_s", "12345", SolrQuery.MOD_ID); final QueryResponse response = server.query(query.getSolrJ()); Assert.assertEquals("false id", newId, response.getResults().get(0).get("id")); Assert.assertEquals("Too many documents", 1, response.getResults().size()); } finally { // delete document server.deleteById(newId); server.commit(); server.optimize(); } }
From source file:net.chaosserver.timelord.swingui.SummaryPanel.java
/** * Updates the text of the total time label in an overly complex * fashion.//from w ww. j a v a2s.c o m */ public void updateTotalTimeLabel() { if (log.isDebugEnabled()) { log.debug("Updating TotalTimeLabel"); } if (isToday()) { int hour = (int) Math.floor(getTimelordDayView().getDayStartTime()); int minute = (int) Math .floor((getTimelordDayView().getDayStartTime() - hour) * DateUtil.MINUTE_IN_HOUR); Calendar dayStart = Calendar.getInstance(); dayStart.setTime(dateDisplayed); dayStart.set(Calendar.HOUR_OF_DAY, hour); dayStart.set(Calendar.MINUTE, minute); dayStart.set(Calendar.SECOND, 0); dayStart.set(Calendar.MILLISECOND, 0); totalTimeLabel.setText("(" + hourDisplay.format(dayStart.getTime()) + " - " + hourDisplay.format(getTimelordDayView().getTimeTrackedTo()) + ") " + DateUtil.formatHours(null, getTimelordDayView().getTotalTimeToday(true))); } else { totalTimeLabel.setText(getTimelordDayView().getTotalTimeToday(true) + ""); } }
From source file:blue.soundObject.jmask.Quantizer.java
public double getValue(double time, double val) { if (!enabled) { return val; }/*w ww .ja v a 2 s .co m*/ double retVal, err, d, r; double localGridSize = gridSizeTableEnabled ? gridSizeTable.getValue(time / duration) : gridSize; double localStrength = strengthTableEnabled ? strengthTable.getValue(time / duration) : strength; double localOffset = offsetTableEnabled ? offsetTable.getValue(time / duration) : offset; // if(localGridSize == 0) { // throw new Exception("GridSize == 0"); // } d = val - localOffset; r = Math.floor((d + localGridSize / 2.0) / localGridSize); err = d / localGridSize - r; retVal = localOffset + (r + err * (1 - localStrength)) * localGridSize; // if(limit) // { // if (erg < g1) erg = localOffset + (r + 1.0 + err*(1-localStrength)) * localGridSize; // if (erg > g2) erg = localOffset + (r - 1.0 + err*(1-localStrength)) * localGridSize; // } return retVal; }
From source file:edu.pitt.csb.stability.StabilitySearch.java
/** * When the size of subsamples is omitted, we use the CPSS approach of Shah and Samworth (2013) * * @param data/*w w w. ja v a2 s . c om*/ * @param gs * @param N Number of subsamples */ public StabilitySearch(DataSet data, DataGraphSearch gs, int N, boolean cpss) { this.data = data; this.gs = gs; this.numSamps = data.getNumRows(); this.numVars = data.getNumColumns(); this.cpss = cpss; if (cpss) { this.subSize = (int) Math.floor(numSamps / 2.0); this.numSubs = N * 2; } else { this.subSize = (int) Math.floor(.8 * numSamps); if (numSamps > 144) subSize = (int) Math.floor(10.0 * Math.sqrt(numSamps)); this.numSubs = N; } this.samps = subSampleNoReplacement(cpss);//numSamps, N/2, subSize); this.thetaMat = DoubleFactory2D.dense.make(numVars, numVars, 0.0); }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Construct the smallest rectangle,/*www . j a v a2s. co m*/ * which include the positions of all statistics in view * @param viewId id of view * @return smallest Rectangle when an StatisticGrafic exist, * null otherwise. */ public static Rectangle getBoundsExternGlobal(Model model, String viewId) { boolean found = false; double minX = (double) Integer.MAX_VALUE / 2; double minY = (double) Integer.MAX_VALUE / 2; double maxX = (double) Integer.MIN_VALUE / 2; double maxY = (double) Integer.MIN_VALUE / 2; String[] id = model.getStatistics().getAllIds(); //System.out.println("Anz. Entities: "+id.length); for (int i = 0; i < id.length; i++) { Statistic statistic = model.getStatistics().get(id[i]); StatisticGrafic statistikGrafic = (StatisticGrafic) statistic.getGrafic(); if (statistikGrafic != null && statistikGrafic.getViewId().equals(viewId)) { found = true; Rectangle r = statistikGrafic.getBoundsExtern(); minX = Math.floor(Math.min(minX, r.getX())); minY = Math.floor(Math.min(minY, r.getY())); maxX = Math.ceil(Math.max(maxX, r.getX() + r.width)); maxY = Math.ceil(Math.max(maxY, r.getY() + r.height)); //System.out.println(statistic.getId()+" "+statistikGrafic.pointExtern.getX()+" "+statistikGrafic.pointExtern.getY()); } } Rectangle r = null; if (found) r = new Rectangle((int) Math.round(minX), (int) Math.round(minY), (int) Math.round(maxX - minX), (int) Math.round(maxY - minY)); //System.out.println("StatisticGrafic: BoundsExtern: "+r); return r; }