Esempio n. 1
0
 /*
  * Returns the argument's ulp (unit in the last place). The size of a ulp of
  * a float value is the positive distance between this value and the float
  * value next larger in magnitude. For non-NaN {@code x},
  * {@code ulp(-x) == ulp(x)}.
  * <p>
  * Special cases:
  * <ul>
  * <li>{@code ulp(+0.0) = Float.MIN_VALUE}</li>
  * <li>{@code ulp(-0.0) = Float.MIN_VALUE}</li>
  * <li>{@code ulp(+infintiy) = infinity}</li>
  * <li>{@code ulp(-infintiy) = infinity}</li>
  * <li>{@code ulp(NaN) = NaN}</li>
  * </ul>
  *
  * @param f
  *            the floating-point value to compute ulp of.
  * @return the size of a ulp of the argument.
  */
 public static float ulp(float f)
 {
     // special cases
     if (Float.isNaN(f))
     {
         return(Float.NaN);
     }
     else if (float.IsInfinity(f))
     {
         return(Float.POSITIVE_INFINITY);
     }
     else if (f == Float.MAX_VALUE || f == -Float.MAX_VALUE)
     {
         return((float)pow(2, 104));
     }
     f = Math.abs(f);
     return(nextafterf(f, Float.MAX_VALUE) - f);
 }
Esempio n. 2
0
        /*
         * Returns the signum function of the argument. If the argument is less than
         * zero, it returns -1.0. If the argument is greater than zero, 1.0 is
         * returned. If the argument is either positive or negative zero, the
         * argument is returned as result.
         * <p>
         * Special cases:
         * <ul>
         * <li>{@code signum(+0.0) = +0.0}</li>
         * <li>{@code signum(-0.0) = -0.0}</li>
         * <li>{@code signum(+infinity) = +1.0}</li>
         * <li>{@code signum(-infinity) = -1.0}</li>
         * <li>{@code signum(NaN) = NaN}</li>
         * </ul>
         *
         * @param f
         *            the value whose signum has to be computed.
         * @return the value of the signum function.
         */
        public static float signum(float f)
        {
            if (Float.isNaN(f))
            {
                return(Float.NaN);
            }
            float sig = f;

            if (f > 0)
            {
                sig = 1.0f;
            }
            else if (f < 0)
            {
                sig = -1.0f;
            }
            return(sig);
        }
Esempio n. 3
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);
 }
Esempio n. 4
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));
     }
 }
Esempio n. 5
0
 /**
  * Converts the specified float to its string representation.
  *
  * @param value
  *            the float.
  * @return the float converted to a string.
  */
 public static String valueOf(float value)
 {
     return(Float.toString(value));
 }
Esempio n. 6
0
 /**
  * Constructs a new {@code AssertionError} with a message based on calling
  * {@link String#valueOf(float)} with the specified float value.
  *
  * @param detailMessage
  *            the value to be converted into the message.
  */
 public AssertionError(float detailMessage) :
     this(Float.toString(detailMessage))
 {
 }
Esempio n. 7
0
 /*
  * Inserts the string representation of the specified {@code float} value at
  * the specified {@code offset}. The {@code float} value is converted to a
  * string according to the rule defined by {@link String#valueOf(float)}.
  *
  * @param offset
  *            the index to insert at.
  * @param f
  *            the {@code float} value to insert.
  * @return this builder.
  * @throws StringIndexOutOfBoundsException
  *             if {@code offset} is negative or greater than the current
  *             {@code length()}.
  * @see String#valueOf(float)
  */
 public StringBuilder insert(int offset, float f)
 {
     insert0(offset, Float.toString(f));
     return(this);
 }
Esempio n. 8
0
 /*
  * Appends the string representation of the specified {@code float} value.
  * The {@code float} value is converted to a string according to the rule
  * defined by {@link String#valueOf(float)}.
  *
  * @param f
  *            the {@code float} value to append.
  * @return this builder.
  * @see String#valueOf(float)
  */
 public StringBuilder append(float f)
 {
     append0(Float.toString(f));
     return(this);
 }
Esempio n. 9
0
 /*
  * Inserts the string representation of the specified float into this buffer
  * at the specified offset.
  *
  * @param index
  *            the index at which to insert.
  * @param f
  *            the float to insert.
  * @return this buffer.
  * @throws StringIndexOutOfBoundsException
  *             if {@code index &lt; 0} or {@code index &gt; length()}.
  */
 public java.lang.StringBuffer insert(int index, float f)
 {
     return(insert(index, Float.toString(f)));
 }
Esempio n. 10
0
 /*
  * Adds the string representation of the specified float to the end of this
  * StringBuffer.
  *
  * @param f
  *            the float to append.
  * @return this StringBuffer.
  * @see String#valueOf(float)
  */
 public java.lang.StringBuffer append(float f)
 {
     return(append(Float.toString(f)));
 }
Esempio n. 11
0
 //, Comparable<Float> {
 public static java.lang.Float valueOf(String d)
 {
     System.Single sysD = Convert.ToSingle(d);
     Float returnValue = new Float(sysD);
     return returnValue;
 }