⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 float.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   *   * @param v the <code>float</code> to compare   * @return whether the argument is <code>NaN</code>   */  public static boolean isNaN(float v)  {    // This works since NaN != NaN is the only reflexive inequality    // comparison which returns true.    return v != v;  }  /**   * Return <code>true</code> if the <code>float</code> has a value   * equal to either <code>NEGATIVE_INFINITY</code> or   * <code>POSITIVE_INFINITY</code>, otherwise return <code>false</code>.   *   * @param v the <code>float</code> to compare   * @return whether the argument is (-/+) infinity   */  public static boolean isInfinite(float v)  {    return v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY;  }  /**   * Return <code>true</code> if the value of this <code>Float</code>   * is the same as <code>NaN</code>, otherwise return <code>false</code>.   *   * @return whether this <code>Float</code> is <code>NaN</code>   */  public boolean isNaN()  {    return isNaN(value);  }  /**   * Return <code>true</code> if the value of this <code>Float</code>   * is the same as <code>NEGATIVE_INFINITY</code> or   * <code>POSITIVE_INFINITY</code>, otherwise return <code>false</code>.   *   * @return whether this <code>Float</code> is (-/+) infinity   */  public boolean isInfinite()  {    return isInfinite(value);  }  /**   * Convert the <code>float</code> value of this <code>Float</code>   * to a <code>String</code>.  This method calls   * <code>Float.toString(float)</code> to do its dirty work.   *   * @return the <code>String</code> representation   * @see #toString(float)   */  public String toString()  {    return toString(value);  }  /**   * Return the value of this <code>Float</code> as a <code>byte</code>.   *   * @return the byte value   * @since 1.1   */  public byte byteValue()  {    return (byte) value;  }  /**   * Return the value of this <code>Float</code> as a <code>short</code>.   *   * @return the short value   * @since 1.1   */  public short shortValue()  {    return (short) value;  }  /**   * Return the value of this <code>Integer</code> as an <code>int</code>.   *   * @return the int value   */  public int intValue()  {    return (int) value;  }  /**   * Return the value of this <code>Integer</code> as a <code>long</code>.   *   * @return the long value   */  public long longValue()  {    return (long) value;  }  /**   * Return the value of this <code>Float</code>.   *   * @return the float value   */  public float floatValue()  {    return value;  }  /**   * Return the value of this <code>Float</code> as a <code>double</code>   *   * @return the double value   */  public double doubleValue()  {    return value;  }  /**   * Return a hashcode representing this Object. <code>Float</code>'s hash   * code is calculated by calling <code>floatToIntBits(floatValue())</code>.   *   * @return this Object's hash code   * @see #floatToIntBits(float)   */  public int hashCode()  {    return floatToIntBits(value);  }  /**   * Returns <code>true</code> if <code>obj</code> is an instance of   * <code>Float</code> and represents the same float value. Unlike comparing   * two floats with <code>==</code>, this treats two instances of   * <code>Float.NaN</code> as equal, but treats <code>0.0</code> and   * <code>-0.0</code> as unequal.   *   * <p>Note that <code>f1.equals(f2)</code> is identical to   * <code>floatToIntBits(f1.floatValue()) ==   *    floatToIntBits(f2.floatValue())</code>.   *   * @param obj the object to compare   * @return whether the objects are semantically equal   */  public boolean equals(Object obj)  {    if (! (obj instanceof Float))      return false;    float f = ((Float) obj).value;    // Avoid call to native method. However, some implementations, like gcj,    // are better off using floatToIntBits(value) == floatToIntBits(f).    // Check common case first, then check NaN and 0.    if (value == f)      return (value != 0) || (1 / value == 1 / f);    return isNaN(value) && isNaN(f);  }  /**   * Convert the float to the IEEE 754 floating-point "single format" bit   * layout. Bit 31 (the most significant) is the sign bit, bits 30-23   * (masked by 0x7f800000) represent the exponent, and bits 22-0   * (masked by 0x007fffff) are the mantissa. This function collapses all   * versions of NaN to 0x7fc00000. The result of this function can be used   * as the argument to <code>Float.intBitsToFloat(int)</code> to obtain the   * original <code>float</code> value.   *   * @param value the <code>float</code> to convert   * @return the bits of the <code>float</code>   * @see #intBitsToFloat(int)   */  // GCJ LOCAL: We diverge from Classpath for efficiency.  public static native int floatToIntBits(float value);  // END GCJ LOCAL  /**   * Convert the float to the IEEE 754 floating-point "single format" bit   * layout. Bit 31 (the most significant) is the sign bit, bits 30-23   * (masked by 0x7f800000) represent the exponent, and bits 22-0   * (masked by 0x007fffff) are the mantissa. This function leaves NaN alone,   * rather than collapsing to a canonical value. The result of this function   * can be used as the argument to <code>Float.intBitsToFloat(int)</code> to   * obtain the original <code>float</code> value.   *   * @param value the <code>float</code> to convert   * @return the bits of the <code>float</code>   * @see #intBitsToFloat(int)   */  // GCJ LOCAL: We diverge from Classpath for efficiency.  public static native int floatToRawIntBits(float value);  // END GCJ LOCAL  /**   * Convert the argument in IEEE 754 floating-point "single format" bit   * layout to the corresponding float. Bit 31 (the most significant) is the   * sign bit, bits 30-23 (masked by 0x7f800000) represent the exponent, and   * bits 22-0 (masked by 0x007fffff) are the mantissa. This function leaves   * NaN alone, so that you can recover the bit pattern with   * <code>Float.floatToRawIntBits(float)</code>.   *   * @param bits the bits to convert   * @return the <code>float</code> represented by the bits   * @see #floatToIntBits(float)   * @see #floatToRawIntBits(float)   */  // GCJ LOCAL: We diverge from Classpath for efficiency.  public static native float intBitsToFloat(int bits);  // END GCJ LOCAL  /**   * Compare two Floats numerically by comparing their <code>float</code>   * values. The result is positive if the first is greater, negative if the   * second is greater, and 0 if the two are equal. However, this special   * cases NaN and signed zero as follows: NaN is considered greater than   * all other floats, including <code>POSITIVE_INFINITY</code>, and positive   * zero is considered greater than negative zero.   *   * @param f the Float to compare   * @return the comparison   * @since 1.2   */  public int compareTo(Float f)  {    return compare(value, f.value);  }  /**   * Behaves like <code>compareTo(Float)</code> unless the Object   * is not an <code>Float</code>.   *   * @param o the object to compare   * @return the comparison   * @throws ClassCastException if the argument is not a <code>Float</code>   * @see #compareTo(Float)   * @see Comparable   * @since 1.2   */  public int compareTo(Object o)  {    return compare(value, ((Float) o).value);  }  /**   * Behaves like <code>new Float(x).compareTo(new Float(y))</code>; in   * other words this compares two floats, special casing NaN and zero,   * without the overhead of objects.   *   * @param x the first float to compare   * @param y the second float to compare   * @return the comparison   * @since 1.4   */  public static int compare(float x, float y)  {    if (isNaN(x))      return isNaN(y) ? 0 : 1;    if (isNaN(y))      return -1;    // recall that 0.0 == -0.0, so we convert to infinities and try again    if (x == 0 && y == 0)      return (int) (1 / x - 1 / y);    if (x == y)      return 0;    return x > y ? 1 : -1;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -