Example usage for java.lang Math floor

List of usage examples for java.lang Math floor

Introduction

In this page you can find the example usage for java.lang Math floor.

Prototype

public static double floor(double a) 

Source Link

Document

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:Coordinate.java

/**
 * The compareTo method compares the receiving object with the specified object and returns a 
 * negative integer, 0, or a positive integer depending on whether the receiving object is 
 * less than, equal to, or greater than the specified object.
 *
 * @param c the event to compare this one to
 *
 * @return  an integer indicating comparison result
 *///  www .  j  a  v  a2s. c  o m
public int compareTo(Coordinate c) {

    String me = this.getLatitudeAsString() + this.getLongitudeAsString();
    String you = c.getLatitudeAsString() + c.getLongitudeAsString();

    Double meDbl = Double.valueOf(me);
    Double youDbl = Double.valueOf(you);

    if (meDbl == youDbl) {
        return 0;
    } else {
        Double tmp = Math.floor(meDbl - youDbl);
        return tmp.intValue();
    }

}

From source file:alignment.BinaryToCSV.java

/**
 * /* w  ww  .  j  av  a  2  s .c om*/
 *
 * @param 
 * @return 
 */
public void computeBlockSize() {
    Nc2 = 3 * LN + 3 * gyro + 3 * mag + 3 * WR;
    System.out.println("Nc2: " + Nc2);
    Bs = Nc2 * 2 + Nc1;
    System.out.println("Bs: " + Bs);
    N = (int) Math.floor((512 - 6 * sync) / (Bs + 2));
    System.out.println("N: " + N);
    Bp = N * (Bs + 2) + 5 * sync;
    System.out.println("Block size: " + Bp);
}

From source file:cc.redberry.core.number.Exponentiation.java

public static Complex findIntegerRoot(Complex base, BigInteger power) {
    BigInteger rDenominator = ((Rational) base.getReal()).getDenominator();
    BigInteger iDenominator = ((Rational) base.getImaginary()).getDenominator();

    BigInteger lcm = rDenominator.gcd(iDenominator);
    lcm = rDenominator.divide(lcm);//from w  w  w .j av a  2s .c  o m
    lcm = lcm.multiply(iDenominator);

    BigInteger lcmRoot = findIntegerRoot(lcm, power);

    if (lcm == null)
        return null;

    base = base.multiply(lcm);

    Complex numericValue = base.pow(1.0 / power.doubleValue());
    double real = numericValue.getReal().doubleValue();
    double imaginary = numericValue.getImaginary().doubleValue();

    int ceilReal = (int) Math.ceil(real), floorReal = (int) Math.floor(real),
            ceilImaginary = (int) Math.ceil(imaginary), floorImaginary = (int) Math.floor(imaginary);

    Complex candidate;
    if ((candidate = new Complex(ceilReal, ceilImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(floorReal, ceilImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(ceilReal, floorImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(floorReal, floorImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    return null;
}

From source file:com.almende.eve.algorithms.Graph.java

/**
 * Gets the random edge./*from   w  w  w.jav a 2  s .  c  om*/
 *
 * @param tag
 *            the tag
 * @return the random edge
 */
@JsonIgnore
@Access(AccessType.PUBLIC)
public Edge getRandomEdge(final @Name("tag") String tag) {
    final Edge[] taggedEdges = getByTag(tag);
    if (taggedEdges.length > 0) {
        return taggedEdges[(int) Math.floor(Math.random() * taggedEdges.length)];
    } else {
        return null;
    }
}

From source file:com.mgmtp.perfload.loadprofiles.util.PlotFileCreator.java

/**
 * Create a time-rate-histogram of events of the given client. The histograms are usually used
 * for diagnostic purposes.//from  w  w  w. j a  va  2  s .co m
 * 
 * @param file
 *            The plot file
 * @param eventList
 *            List of events from which the histogram is derived after applying a filter on the
 *            operation
 * @param clientId
 *            Id of the client, used as filter to use only events in the histogram, which have
 *            this clientId assigned.
 * @param nBin
 *            Number of bins of the resulting histogram.
 * @param xLow
 *            time value of the left boundary of the lowest bin of the resulting histogram
 * @param xUp
 *            time value of the right boundary of the highest bin of the resulting histogram
 * @param timeUnitPlot
 *            The time unit of the resulting plot
 */
public static void createClientHistogram(final File file, final Collection<LoadEvent> eventList,
        final int clientId, final int nBin, final double xLow, final double xUp, final String timeUnitPlot)
        throws IOException {
    double timeScalingFactor = LoadCurveCalculator.getTimeScalingFactor(LoadCurveCalculator.timeUnit_hour,
            timeUnitPlot);

    double[] xhistoLow = new double[nBin];
    double[] xhistoUp = new double[nBin];
    int[] yhisto = new int[nBin];

    double delta = nBin / (xUp - xLow);
    for (int iBin = 0; iBin < nBin; iBin++) {
        xhistoLow[iBin] = iBin / delta + xLow;
        xhistoUp[iBin] = (iBin + 1) / delta + xLow;
    }
    for (LoadEvent event : eventList) {
        if (event.getClientId() == clientId) {
            double time = timeScalingFactor * event.getTime();
            int xBin = (int) Math.floor((time - xLow) * delta);
            if (xBin >= 0 && xBin < nBin) {
                yhisto[xBin] += event.getOperation().getRelativeClientLoad();
            } else {
                log.warn("Value " + time + " outside range [" + xLow + ", " + xUp + ")");
            }
        }
    }

    // create plot data
    double[] x = new double[nBin * 2];
    double[] y = new double[nBin * 2];

    int plotBin = 0;
    for (int iBin = 0; iBin < nBin; iBin++) {
        x[plotBin] = xhistoLow[iBin];
        y[plotBin] = yhisto[iBin] / (xhistoUp[iBin] - xhistoLow[iBin]);
        plotBin++;
        x[plotBin] = xhistoUp[iBin];
        y[plotBin] = yhisto[iBin] / (xhistoUp[iBin] - xhistoLow[iBin]);
        plotBin++;
    }
    createPlot(file, x, y, "time " + timeUnitPlot, "Histogram Client " + clientId);
}

From source file:eu.matejkormuth.rpgdavid.starving.Region.java

public int getMinYFloor() {
    return (int) Math.floor(this.minVector.getY());
}

From source file:playground.johannes.snowball.Histogram.java

private void fillBins() {
    if (modified) {
        double min, max, width;
        int size;

        if (bounds != null) {
            min = bounds[0];/*from  w w w .  j ava 2 s .co  m*/
            max = bounds[1];
        } else {
            double minmax[] = getMinMax();
            min = minmax[0];
            max = minmax[1];
        }
        if (binWidth > 0) {
            size = (int) Math.ceil((max - min) / (double) binWidth);
            width = binWidth;
        } else {
            size = bincount;
            width = (max - min) / (double) bincount;
        }

        bins = new DoubleArrayList();
        bins.setSize(size + 1);
        for (int i = 0; i < values.size(); i++) {
            double value = values.get(i);
            if (value >= min && value <= max) {
                int idx = (int) Math.floor((values.get(i) - min) / width);
                bins.set(idx, bins.get(idx) + weights.get(i));
            }
        }

        modified = false;
    }
}

From source file:edu.scripps.fl.curves.plot.GCurvePlot.java

public String getURL() {
    XYLineChart chart = GCharts.newXYLineChart(lines);
    chart.setLegendPosition(LegendPosition.BOTTOM);
    chart.setSize(getWidth(), getHeight());
    chart.setTitle(title, Color.BLACK, 14);

    // Defining axis info and styles
    AxisStyle axisStyle = AxisStyle.newAxisStyle(Color.BLACK, 12, AxisTextAlignment.CENTER);
    AxisLabels yAxis = AxisLabelsFactory.newNumericRangeAxisLabels(-25, 125, 25);
    yAxis.setAxisStyle(axisStyle);/*  w w w . j a va2 s.c om*/

    AxisLabels xAxis = AxisLabelsFactory.newNumericRangeAxisLabels(Math.floor(minX), Math.ceil(maxX), 1.0);
    xAxis.setAxisStyle(axisStyle);

    chart.addYAxisLabels(yAxis);
    chart.addXAxisLabels(xAxis);
    //        chart.setGrid(100, 6.78, 5, 0);

    // Defining background and chart fills.
    chart.setBackgroundFill(Fills.newSolidFill(getBackgroundColor()));
    chart.setAreaFill(Fills.newSolidFill(getBackgroundColor()));
    String url = chart.toURLString();
    return url;
}

From source file:net.ae97.pokebot.extensions.scrolls.PlayerCommand.java

private String parseTime(int time) {
    if (time < 0) {
        return "Never played";
    }//from www .ja va  2s .c o m
    if (time < 10) {
        return "Just now";
    }
    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:com.garyclayburg.UserRestSmokeTest.java

@Ignore
@Test/*ww  w.  jav a  2s  .co m*/
public void testJsonutf8Apache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/json;charset=UTF-8");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}