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:Util.java

public static double mod(double x, double y) {
    double m = x;
    if (y != 0) {
        m = x - y * Math.floor(x / y);
    }/*w w w .  j a v  a2 s . c  o m*/
    return m;
}

From source file:com.nebhale.cyclinglibrary.util.GooglePolylineEncoder.java

private String[] encode(Double[] point, EncodingContext context) {
    int e5Latitude = (int) Math.floor(point[0] * 1e5);
    int e5Longitude = (int) Math.floor(point[1] * 1e5);

    int differenceLatitude = e5Latitude - context.previousLatitude;
    int differenceLongitude = e5Longitude - context.previousLongitude;

    context.previousLatitude = e5Latitude;
    context.previousLongitude = e5Longitude;

    String encodedLatitude = encodeSignedNumber(differenceLatitude);
    String encodedLongitude = encodeSignedNumber(differenceLongitude);

    return new String[] { encodedLatitude, encodedLongitude };
}

From source file:cf.client.model.ApplicationInstance.java

@JsonCreator
public ApplicationInstance(@JsonProperty("state") String state, @JsonProperty("since") double since,
        @JsonProperty("debug_ip") String debugIp, @JsonProperty("debug_port") Integer debugPort,
        @JsonProperty("console_ip") String consoleIp, @JsonProperty("console_port") Integer consolePort) {
    State stateValue = null;/*from   w ww.j  a  v  a2  s. co m*/
    try {
        stateValue = State.valueOf(state.toUpperCase());
    } catch (IllegalArgumentException e) {
        stateValue = State.UNKNOWN;
    }
    this.state = stateValue;
    this.since = new Date((long) Math.floor(since * 1000));
    this.debugAddress = (debugIp == null || debugPort == null) ? null
            : new InetSocketAddress(debugIp, debugPort);
    this.consoleAddress = (consoleIp == null || consolePort == null) ? null
            : new InetSocketAddress(consoleIp, consolePort);
}

From source file:org.whispersystems.textsecuregcm.limits.LeakyBucket.java

private int getUpdatedSpaceRemaining() {
    long elapsedTime = System.currentTimeMillis() - this.lastUpdateTimeMillis;

    return Math.min(this.bucketSize,
            (int) Math.floor(this.spaceRemaining + (elapsedTime * this.leakRatePerMillis)));
}

From source file:com.galenframework.specs.RangeValue.java

@Override
public String toString() {
    if (precision > 0) {
        int d = (int) Math.pow(10, precision);

        int firstPart = (int) Math.floor(value / d);
        int secondPart = Math.abs(value % d);

        StringBuilder builder = new StringBuilder();
        builder.append(Integer.toString(firstPart));
        builder.append('.');

        String digits = Integer.toString(secondPart);
        for (int i = digits.length(); i < precision; i++) {
            builder.append('0');
        }/*from ww w  . j  a  va2s  . c om*/
        builder.append(digits);
        return builder.toString();
    } else {
        return Integer.toString(value);
    }
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

private static int getPowerOfTwoForSampleRatio(double ratio) {
    int k = Integer.highestOneBit((int) Math.floor(ratio));

    if (k == 0)//from   w w  w  .jav  a2 s.c  o  m
        return 1;
    else
        return k;
}

From source file:us.putney.controllers.SampleServiceController.java

static Map getPower() {
    Map<String, Object> power = new HashMap<String, Object>();
    power.put("name", powers[(int) Math.floor(Math.random() * powers.length)]);
    power.put("level", (int) (Math.random() * 10));
    return power;
}

From source file:com.mapr.synth.samplers.SequenceSampler.java

@Override
public JsonNode sample() {
    Preconditions.checkState(array != null || base != null, "Need to specify either base or array");
    ArrayNode r = nodeFactory.arrayNode();
    if (base != null) {
        int n = (int) Math.floor(-averageLength * Math.log(gen.nextDouble()));
        for (int i = 0; i < n; i++) {
            r.add(base.sample());/*from   w  w  w .  j ava2 s.  c  o  m*/
        }
    } else {
        for (FieldSampler fieldSampler : array) {
            r.add(fieldSampler.sample());
        }
    }
    return r;
}

From source file:com.proofpoint.units.DataSize.java

public long roundTo(Unit unit) {
    double rounded = Math.floor(getValue(unit) + 0.5d);
    Preconditions.checkArgument(rounded <= Long.MAX_VALUE,
            "size is too large to be represented in requested unit as a long");
    return (long) rounded;
}

From source file:com.comphenix.xp.SampleRange.java

public int getMinimum() {
    return (int) Math.floor(start);
}