Java examples for java.lang:Math Number
Returns the floating-point number adjacent to the first argument in the direction of the second argument.
/**/*from w ww . j a va2s. c om*/ * Java Modular Image Synthesis Toolkit (JMIST) * Copyright (C) 2008-2013 Bradley W. Kimmel * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; public class Main{ /** * Implementation of methods from <code>java.lang.Math</code> not available * in Java 1.5. */ private static final MathImpl impl = JAVA_SPEC >= 1.6 ? new MathImplJava6() : new MathImplJava5(); /** * Returns the floating-point number adjacent to the first * argument in the direction of the second argument. If both * arguments compare as equal the second argument is returned. * * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * * <li> If both arguments are signed zeros, <code>direction</code> * is returned unchanged (as implied by the requirement of * returning the second argument if the arguments compare as * equal). * * <li> If <code>start</code> is * ±<code>Double.MIN_VALUE</code> and <code>direction</code> * has a value such that the result should have a smaller * magnitude, then a zero with the same sign as <code>start</code> * is returned. * * <li> If <code>start</code> is infinite and * <code>direction</code> has a value such that the result should * have a smaller magnitude, <code>Double.MAX_VALUE</code> with the * same sign as <code>start</code> is returned. * * <li> If <code>start</code> is equal to ± * <code>Double.MAX_VALUE</code> and <code>direction</code> has a * value such that the result should have a larger magnitude, an * infinity with same sign as <code>start</code> is returned. * </ul> * * @param start starting floating-point value * @param direction value indicating which of * <code>start</code>'s neighbors or <code>start</code> should * be returned * @return The floating-point number adjacent to <code>start</code> in the * direction of <code>direction</code>. */ public static double nextAfter(double start, double direction) { return impl.nextAfter(start, direction); } /** * Returns the floating-point number adjacent to the first * argument in the direction of the second argument. If both * arguments compare as equal, the second argument is returned. * * <p> * Special cases: * <ul> * <li> If either argument is a NaN, then NaN is returned. * * <li> If both arguments are signed zeros, a <code>float</code> * zero with the same sign as <code>direction</code> is returned * (as implied by the requirement of returning the second argument * if the arguments compare as equal). * * <li> If <code>start</code> is * ±<code>Float.MIN_VALUE</code> and <code>direction</code> * has a value such that the result should have a smaller * magnitude, then a zero with the same sign as <code>start</code> * is returned. * * <li> If <code>start</code> is infinite and * <code>direction</code> has a value such that the result should * have a smaller magnitude, <code>Float.MAX_VALUE</code> with the * same sign as <code>start</code> is returned. * * <li> If <code>start</code> is equal to ± * <code>Float.MAX_VALUE</code> and <code>direction</code> has a * value such that the result should have a larger magnitude, an * infinity with same sign as <code>start</code> is returned. * </ul> * * @param start starting floating-point value * @param direction value indicating which of * <code>start</code>'s neighbors or <code>start</code> should * be returned * @return The floating-point number adjacent to <code>start</code> in the * direction of <code>direction</code>. */ public static float nextAfter(float start, double direction) { return impl.nextAfter(start, direction); } }