List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:net.ae97.pokebot.extensions.scrolls.PriceCommand.java
private String parseTime(int time) { if (time < 10) { return "Just now"; }//from ww w . j av a 2s . c o m String[] strs = new String[] { "second", "minute", "hour", "day", "week", "month" }; int[] duration = new int[] { 1, 60, 3600, 86400, 604800, 2630880 }; double no = 0; int i; for (i = duration.length - 1; (i >= 0) && ((no = time / duration[i]) < 1); i--) { } int t = (int) Math.floor(no); return t + " " + strs[i] + ((t > 1) ? "s" : "") + " ago"; }
From source file:no.met.jtimeseries.marinogram.MarinogramCurrentPlot.java
private XYPlot createPlot(TimeZone timezone, boolean plotCurrentDirection, boolean plotCurrentSpeed) { ChartPlotter plotter = new ChartPlotter(); // default setting plotter.setHeight(this.getHeight()); plotter.setWidth(this.getWidth()); plotter.setPlotDefaultProperties("", ""); Color currentSpeedColor = new Color(142, 25, 131); Color currentDirectionColor = new Color(142, 25, 131); // plot style PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Current"); PlotStyle plotStyle;//from www . java2 s .c o m NumberPhenomenon currentDirection = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.CurrentDirection.toString(), NumberPhenomenon.class); NumberPhenomenon currentSpeed = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class); if (currentSpeed == null || currentDirection == null) { return null; } currentSpeed = currentSpeed.scaling(100); double tick = (currentSpeed.getMaxValue() - currentSpeed.getMinValue()) / 2; tick = Math.ceil(tick / 10) * 10; double lowBound = Math.floor(currentSpeed.getMinValue() / (tick)) * (tick); //The minimum scale is 0 lowBound = lowBound < 0 ? 0 : lowBound; lowBound = lowBound - tick / 2; double upperBound = lowBound + tick * 4; // reference the range axis NumberAxis leftNumberAxis = new NumberAxis(); leftNumberAxis.setLabel(messages.getString("parameter.current") + " (cm/s)"); leftNumberAxis.setLabelPaint(currentSpeedColor); leftNumberAxis.setTickLabelPaint(currentSpeedColor); leftNumberAxis.setLowerBound(lowBound); leftNumberAxis.setUpperBound(upperBound); leftNumberAxis.setTickUnit(new NumberTickUnit(tick)); NumberAxis rightNumberAxis = new NumberAxis(); rightNumberAxis.setLabel(messages.getString("label.knots")); rightNumberAxis.setLabelPaint(currentSpeedColor); rightNumberAxis.setTickLabelPaint(currentSpeedColor); lowBound = lowBound / 100.0 / KNOT; upperBound = upperBound / 100.0 / KNOT; rightNumberAxis.setLowerBound(lowBound); rightNumberAxis.setUpperBound(upperBound); rightNumberAxis.setTickUnit(new NumberTickUnit(tick / 100.0 / KNOT)); NumberFormat formatter = new DecimalFormat("#0.00"); rightNumberAxis.setNumberFormatOverride(formatter); List<Date> shortTermTimeList = this.getShortTermTime(currentDirection.getTime().get(0)); //set thte plot current speed color to be transparent if show current speed is false if (!plotCurrentSpeed) { currentSpeedColor = new Color(0, 0, 0, 0); } // plot style BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f, new float[] { 2.0f, 6.0f }, 0.0f); plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(dottedStroke) .seriesColor(currentSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build(); //Draw the current direction even if plotCurrentSpeed is false (but with transparent in such a case) //for the purpose to keep the same background grid and tick label on the y-axis //no matter the wave height is shown or not plotter.addLineChart(TimeBase.SECOND, currentSpeed, plotStyle); plotter.getPlot().setRangeAxis(1, rightNumberAxis); plotter.getPlot().setOutlineVisible(true); Date minDate = shortTermTimeList.get(0); Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1); plotter.setDomainRange(minDate, maxDate); plotter.setDomainDateFormat(timezone, "HH"); // set domain range after (must) plot all the data plotter.addHourBasedDomainGridLines(); // invisible domain axis plotter.getPlot().getDomainAxis().setTickLabelsVisible(false); // add markers plotter.addDomainMarkers(shortTermTimeList, timezone, locale); if (plotCurrentDirection) { List<Date> symbolTimes = Utility.filterMinimumHourInterval(currentDirection.getTime(), 2, 1); InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes); currentDirection.filter(symbolTimesFilter); currentSpeed = null; if (plotCurrentSpeed) { currentSpeed = getOceanForecastDataModel().getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class); currentSpeed.filter(symbolTimesFilter); currentSpeed = currentSpeed.scaling(1 / 100.0 / KNOT); } plotStyle = currentStyleBuilder.seriesColor(currentDirectionColor).build(); plotter.addArrowDirectionPlot(currentDirection, currentSpeed, 2, plotStyle); } plotter.getPlot().setRangeZeroBaselineVisible(false); return plotter.getPlot(); }
From source file:geogebra.kernel.AlgoBinomial.java
private double BinomLog(double n, double r) { // exact for n<=37 // also if r<2.8+Math.exp((250-n)/100) && n<59000 // eg Binom2(38,19) is wrong return Math.floor( 0.5 + Math.exp(Gamma.logGamma(n + 1d) - Gamma.logGamma(r + 1) - Gamma.logGamma((n - r) + 1))); }
From source file:gdsc.smlm.results.DensityManager.java
private void initialise(float[] xcoord, float[] ycoord, Rectangle bounds) { if (xcoord == null || ycoord == null || xcoord.length == 0 || xcoord.length != ycoord.length) throw new IllegalArgumentException("Results are null or empty or mismatched in length"); this.xcoord = xcoord; this.ycoord = ycoord; // Assign localisations & get min bounds minXCoord = Float.POSITIVE_INFINITY; minYCoord = Float.POSITIVE_INFINITY; for (int i = 0; i < xcoord.length; i++) { if (minXCoord > xcoord[i]) minXCoord = xcoord[i];/*from w ww . j ava 2s . c o m*/ if (minYCoord > ycoord[i]) minYCoord = ycoord[i]; } // Round down and shift to origin minXCoord = (int) Math.floor(minXCoord); minYCoord = (int) Math.floor(minYCoord); // Get max bounds maxXCoord = 0; maxYCoord = 0; for (int i = 0; i < xcoord.length; i++) { xcoord[i] -= minXCoord; ycoord[i] -= minYCoord; if (maxXCoord < xcoord[i]) maxXCoord = xcoord[i]; if (maxYCoord < ycoord[i]) maxYCoord = ycoord[i]; } // Store the area of the input results area = bounds.width * bounds.height; }
From source file:edu.scripps.fl.curves.plot.CurvePlot.java
protected void addCurve(Curve curve, YIntervalSeries validSeries, YIntervalSeries invalidSeries, FitFunction fitFunction, double min, double max) { MyXYErrorRenderer renderer = (MyXYErrorRenderer) plot.getRenderer(); Paint paint = plot.getDrawingSupplier().getNextPaint(); addSeries(validSeries, paint, true, true); if (isDisplayInvalidPoints() && invalidSeries.getItemCount() > 0) { int idx = addSeries(invalidSeries, paint, true, false); float size = (float) DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[0].getBounds().getWidth(); DrawingSupplier ds = this.getDrawingSupplier(); if (ds instanceof CurvePlotDrawingSupplier) size = (float) ((CurvePlotDrawingSupplier) ds).getShapeSize() / 2; size = (float) Math.floor((size - 1) / 2); renderer.setSeriesShape(idx, ShapeUtilities.createDiagonalCross(size, size)); }//from w ww . jav a 2 s . c o m if (null != fitFunction) try { YIntervalSeries functionSeries = sampleFunction2DToSeries(curve, fitFunction, min, max, getWidth(), (Comparable<?>) (dataset.getSeriesCount() + 1)); addSeries(functionSeries, paint, false, false); } catch (NullPointerException ex) { ex.printStackTrace(); } }
From source file:me.azenet.UHPlugin.timers.UHTimer.java
/** * Updates the timer./*ww w .ja v a 2s . c o m*/ */ public void update() { if (running && !paused) { oldHoursLeft = hoursLeft; oldMinutesLeft = minutesLeft; oldSecondsLeft = secondsLeft; long timeSinceStart = System.currentTimeMillis() - this.startTime; // ms if (timeSinceStart >= getDuration() * 1000) { stop(true); } else { Integer countSecondsLeft = (int) (getDuration() - Math.floor(timeSinceStart / 1000)); secondsLeft = countSecondsLeft % 60; minutesLeft = (countSecondsLeft % 3600) / 60; hoursLeft = (int) Math.floor(countSecondsLeft / 3600); } } }
From source file:net.sourceforge.fenixedu.util.InquiriesUtil.java
public static String formatAnswer(final Double answer) { double ans = answer.doubleValue(); if (ans > 0) { return Math.floor(ans) == ans ? String.valueOf(answer.intValue()) : String.valueOf(ans); }//from w w w . j a va2s .c o m return "-"; }
From source file:ceptraj.tool.Bearing.java
public static double modifyBearing(double bearing, double modifyVal) { bearing += modifyVal;//w ww .j av a2s .com if (bearing >= 0) { if (bearing <= Constants.TOTAL_DEGREES) { return bearing; } else if (bearing < (Constants.TOTAL_DEGREES + Constants.TOTAL_DEGREES)) { return bearing - Constants.TOTAL_DEGREES; } } else { if (bearing > -Constants.TOTAL_DEGREES) { return bearing + Constants.TOTAL_DEGREES; } } return bearing - 360 * Math.floor(bearing / 360); }
From source file:juicebox.tools.utils.juicer.arrowhead.MatrixTriangles.java
/** * calculate Bnew, the block score matrix. it's a combination of 3 matrices * * @param matrix/*from w w w . jav a 2 s.com*/ */ public MatrixTriangles(RealMatrix matrix) { int n = Math.min(matrix.getRowDimension(), matrix.getColumnDimension()); up = MatrixTools.cleanArray2DMatrix(n); upSign = MatrixTools.cleanArray2DMatrix(n); upSquared = MatrixTools.cleanArray2DMatrix(n); lo = MatrixTools.cleanArray2DMatrix(n); loSign = MatrixTools.cleanArray2DMatrix(n); loSquared = MatrixTools.cleanArray2DMatrix(n); MatrixTools.setNaNs(matrix, 0); //int window= matrix.getRowDimension(); RealMatrix matrixElementwiseSquared = MatrixTools.elementBasedMultiplication(matrix, matrix); RealMatrix signMatrix = MatrixTools.sign(matrix); RealMatrix onesMatrix = MatrixTools.ones(n); //System.out.println("msign "+ matrix.getNorm()); //System.out.println("sign " + signMatrix.getNorm()); // Matrices used as dynamic programming lookups. // "R" matrices are sums of the columns up to that point: R(1,5) is sum of // column 5 from diagonal (row 5) up to row 1 // "U" matrices are sums of the rows up to the point: U(1,5) is sum of row 5 // from diagonal (col 1) up to col 5 // We want mean, mean of sign, and variance, so we are doing the sum then // dividing by counts RealMatrix rSum = DynamicProgrammingUtils.right(matrix, n); RealMatrix rSign = DynamicProgrammingUtils.right(signMatrix, n); RealMatrix rSquared = DynamicProgrammingUtils.right(matrixElementwiseSquared, n); RealMatrix rCount = DynamicProgrammingUtils.right(onesMatrix, n); RealMatrix uSum = DynamicProgrammingUtils.upper(matrix, n); RealMatrix uSign = DynamicProgrammingUtils.upper(signMatrix, n); RealMatrix uSquared = DynamicProgrammingUtils.upper(matrixElementwiseSquared, n); RealMatrix uCount = DynamicProgrammingUtils.upper(onesMatrix, n); RealMatrix upCount = MatrixTools.cleanArray2DMatrix(n); RealMatrix loCount = MatrixTools.cleanArray2DMatrix(n); // Upper triangle for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int bottom = (int) Math.floor((j - i + 1) / 2); // add half of column up.setEntry(i, j, up.getEntry(i, j - 1) + rSum.getEntry(i, j) - rSum.getEntry(i + bottom, j)); upSign.setEntry(i, j, upSign.getEntry(i, j - 1) + rSign.getEntry(i, j) - rSign.getEntry(i + bottom, j)); upSquared.setEntry(i, j, upSquared.getEntry(i, j - 1) + rSquared.getEntry(i, j) - rSquared.getEntry(i + bottom, j)); upCount.setEntry(i, j, upCount.getEntry(i, j - 1) + rCount.getEntry(i, j) - rCount.getEntry(i + bottom, j)); } } // Normalize MatrixTools.replaceValue(upCount, 0, 1); up = MatrixTools.elementBasedDivision(up, upCount); upSign = MatrixTools.elementBasedDivision(upSign, upCount); upSquared = MatrixTools.elementBasedDivision(upSquared, upCount); // Lower triangle for (int a = 0; a < n; a++) { for (int b = a + 1; b < n; b++) { int val = (int) Math.floor((b - a + 1) / 2); int endpt = Math.min(2 * b - a, n - 1); loCount.setEntry(a, b, loCount.getEntry(a, b - 1) + uCount.getEntry(b, endpt) - rCount.getEntry(a + val, b)); lo.setEntry(a, b, lo.getEntry(a, b - 1) + uSum.getEntry(b, endpt) - rSum.getEntry(a + val, b)); loSign.setEntry(a, b, loSign.getEntry(a, b - 1) + uSign.getEntry(b, endpt) - rSign.getEntry(a + val, b)); loSquared.setEntry(a, b, loSquared.getEntry(a, b - 1) + uSquared.getEntry(b, endpt) - rSquared.getEntry(a + val, b)); } } // Normalize MatrixTools.replaceValue(loCount, 0, 1); lo = MatrixTools.elementBasedDivision(lo, loCount); loSign = MatrixTools.elementBasedDivision(loSign, loCount); loSquared = MatrixTools.elementBasedDivision(loSquared, loCount); initialMatricesNotGenerated = false; }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static double funcFloor(double x) { return Math.floor(x); }