Пример #1
0
        /*
         * Returns the absolute value of the argument.
         * <p>
         * Special cases:
         * <ul>
         * <li>{@code abs(-0.0) = +0.0}</li>
         * <li>{@code abs(+infinity) = +infinity}</li>
         * <li>{@code abs(-infinity) = +infinity}</li>
         * <li>{@code abs(NaN) = NaN}</li>
         * </ul>
         *
         * @param f
         *            the value whose absolute value has to be computed.
         * @return the argument if it is positive, otherwise the negation of the
         *         argument.
         */
        public static float abs(float f)
        {
            int bits = Float.floatToIntBits(f);

            bits &= 0x7fffffff;
            return(Float.intBitsToFloat(bits));
        }
Пример #2
0
 /*
  * Answers the next larger float value to d.
  *
  * @param f
  *            the float value to start
  * @return the next larger float value of d.
  *
  * @since 1.6
  */
 public static float nextUp(float f)
 {
     if (Float.isNaN(f))
     {
         return(Float.NaN);
     }
     if ((f == Float.POSITIVE_INFINITY))
     {
         return(Float.POSITIVE_INFINITY);
     }
     if (0 == f)
     {
         return(Float.MIN_VALUE);
     }
     else if (0 < f)
     {
         return(Float.intBitsToFloat(Float.floatToIntBits(f) + 1));
     }
     else
     {
         return(Float.intBitsToFloat(Float.floatToIntBits(f) - 1));
     }
 }