Example usage for java.lang Math nextUp

List of usage examples for java.lang Math nextUp

Introduction

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

Prototype

public static float nextUp(float f) 

Source Link

Document

Returns the floating-point value adjacent to f in the direction of positive infinity.

Usage

From source file:Main.java

public static void main(String[] args) {
    // Returns the greater adjacent of a double
    double greaterAdjacent = Math.nextUp(123.0);
    System.out.println("Math.nextUp (123.0) = " + greaterAdjacent);
}

From source file:Main.java

public static void main(String[] args) {
    double x = 123456.7;
    double y = -123.45;

    // print the next floating numbers towards positive infinity
    System.out.println("Math.nextUp(" + x + ")=" + Math.nextUp(x));
    System.out.println("Math.nextUp(" + y + ")=" + Math.nextUp(y));

}

From source file:Main.java

public static void main(String[] args) {

    float x = 12345.123f;
    float y = 123.123456f;

    // print the next floating numbers towards positive infinity
    System.out.println("Math.nextUp(" + x + ")=" + Math.nextUp(x));
    System.out.println("Math.nextUp(" + y + ")=" + Math.nextUp(y));

}

From source file:org.apache.commons.rng.examples.sampling.UniformSamplingVisualCheck.java

/**
 * Program entry point./*from  w w w .j  a v a2  s. c  om*/
 *
 * @param args Unused.
 */
public static void main(String[] args) {
    final float lo = 0.1f;
    final int bands = 2;
    float hi = lo;
    for (int i = 0; i < bands; i++) {
        hi = Math.nextUp(hi);
    }
    System.out.printf("# lo=%.10e hi=%.10e", lo, hi);
    System.out.println();

    final UniformSamplingVisualCheck app = new UniformSamplingVisualCheck();

    while (true) {
        System.out.printf("%.16e\t", app.rng.nextDouble());

        for (ContinuousSampler s : app.samplers) {
            while (true) {
                final double r = s.sample();
                if (r < lo || r > hi) {
                    // Discard numbers outside the tiny region.
                    continue;
                }

                System.out.printf("%.16e ", r);
                break;
            }
        }

        System.out.println();
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.TrainingSetServiceImpl.java

/**
 * to avoid retrieving too many records on the score boundary
 * /*from   w  ww.j a  va2  s.  com*/
 * @param number
 * @return
 */
private Double getUpperDoubleValue(Double number) {
    return Math.nextUp(number);
}

From source file:lineage2.gameserver.model.quest.QuestState.java

/**
 * Method rollDrop.//ww w.  java2  s . c o m
 * @param min int
 * @param max int
 * @param calcChance double
 * @return int
 */
public int rollDrop(int min, int max, double calcChance) {
    if ((calcChance <= 0) || (min <= 0) || (max <= 0)) {
        return 0;
    }
    int dropmult = 1;
    calcChance *= getRateQuestsDrop();
    if (getQuest().getParty() > Quest.PARTY_NONE) {
        Player player = getPlayer();
        if (player.getParty() != null) {
            calcChance *= Config.ALT_PARTY_BONUS[player.getParty().getMemberCountInRange(player,
                    Config.ALT_PARTY_DISTRIBUTION_RANGE) - 1];
        }
    }
    if (calcChance > 100) {
        if ((int) Math.ceil(calcChance / 100) <= (calcChance / 100)) {
            calcChance = Math.nextUp(calcChance);
        }
        dropmult = (int) Math.ceil(calcChance / 100);
        calcChance = calcChance / dropmult;
    }
    return Rnd.chance(calcChance) ? Rnd.get(min * dropmult, max * dropmult) : 0;
}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

/**
 * Computes the set of axis labels to show given start and stop boundaries and an ideal number
 * of stops between these boundaries.//from  www.  j  a  v  a2  s. c  o  m
 *
 * @param start    The minimum extreme (e.g. the left edge) for the axis.
 * @param stop     The maximum extreme (e.g. the right edge) for the axis.
 * @param steps    The ideal number of stops to create. This should be based on available screen
 *                 space; the more space there is, the more stops should be shown.
 * @param outStops The destination {@link AxisStops} object to populate.
 */
private static void computeAxisStops(float start, float stop, int steps, AxisStops outStops) {
    double range = stop - start;
    if (steps == 0 || range <= 0) {
        outStops.stops = new float[] {};
        outStops.numStops = 0;
        return;
    }

    double rawInterval = range / steps;
    double interval = roundToOneSignificantFigure(rawInterval);
    double intervalMagnitude = Math.pow(10, (int) Math.log10(interval));
    int intervalSigDigit = (int) (interval / intervalMagnitude);
    if (intervalSigDigit > 5) {
        // Use one order of magnitude higher, to avoid intervals like 0.9 or 90
        interval = Math.floor(10 * intervalMagnitude);
    }

    double first = Math.ceil(start / interval) * interval;
    double last = Math.nextUp(Math.floor(stop / interval) * interval);

    double f;
    int i;
    int n = 0;
    for (f = first; f <= last; f += interval) {
        ++n;
    }

    outStops.numStops = n;

    if (outStops.stops.length < n) {
        // Ensure stops contains at least numStops elements.
        outStops.stops = new float[n];
    }

    for (f = first, i = 0; i < n; f += interval, ++i) {
        outStops.stops[i] = (float) f;
    }

    if (interval < 1) {
        outStops.decimals = (int) Math.ceil(-Math.log10(interval));
    } else {
        outStops.decimals = 0;
    }
}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

/**
 * Ensures that current viewport is inside the viewport extremes defined by {@link #AXIS_X_MIN},
 * {@link #AXIS_X_MAX}, {@link #AXIS_Y_MIN} and {@link #AXIS_Y_MAX}.
 *//*from w  ww  .ja va  2  s. c o  m*/
private void constrainViewport() {
    mCurrentViewport.left = Math.max(AXIS_X_MIN, mCurrentViewport.left);
    mCurrentViewport.top = Math.max(AXIS_Y_MIN, mCurrentViewport.top);
    mCurrentViewport.bottom = Math.max(Math.nextUp(mCurrentViewport.top),
            Math.min(AXIS_Y_MAX, mCurrentViewport.bottom));
    mCurrentViewport.right = Math.max(Math.nextUp(mCurrentViewport.left),
            Math.min(AXIS_X_MAX, mCurrentViewport.right));
}