Пример #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
 /*
  * Returns the most negative (closest to negative infinity) of the two
  * arguments.
  * <p>
  * Special cases:
  * <ul>
  * <li>{@code min(NaN, (anything)) = NaN}</li>
  * <li>{@code min((anything), NaN) = NaN}</li>
  * <li>{@code min(+0.0, -0.0) = -0.0}</li>
  * <li>{@code min(-0.0, +0.0) = -0.0}</li>
  * </ul>
  *
  * @param f1
  *            the first argument.
  * @param f2
  *            the second argument.
  * @return the smaller of {@code f1} and {@code f2}.
  */
 public static float min(float f1, float f2)
 {
     if (f1 > f2)
     {
         return(f2);
     }
     if (f1 < f2)
     {
         return(f1);
     }
     /* if either arg is NaN, return NaN */
     if (f1 != f2)
     {
         return(Float.NaN);
     }
     /* min( +0.0,-0.0) == -0.0 */
     if (f1 == 0.0f &&
         ((Float.floatToIntBits(f1) | Float.floatToIntBits(f2)) & 0x80000000) != 0)
     {
         return(0.0f * (-1.0f));
     }
     return(f1);
 }
Пример #3
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));
     }
 }