?? double.java
字號:
/** * Return <code>true</code> if the <code>double</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>double</code> to compare * @return whether the argument is (-/+) infinity. */ public static boolean isInfinite(double v) { return v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY; } /** * Return <code>true</code> if the value of this <code>Double</code> * is the same as <code>NaN</code>, otherwise return <code>false</code>. * * @return whether this <code>Double</code> is <code>NaN</code> */ public boolean isNaN() { return isNaN(value); } /** * Return <code>true</code> if the value of this <code>Double</code> * is the same as <code>NEGATIVE_INFINITY</code> or * <code>POSITIVE_INFINITY</code>, otherwise return <code>false</code>. * * @return whether this <code>Double</code> is (-/+) infinity */ public boolean isInfinite() { return isInfinite(value); } /** * Convert the <code>double</code> value of this <code>Double</code> * to a <code>String</code>. This method calls * <code>Double.toString(double)</code> to do its dirty work. * * @return the <code>String</code> representation * @see #toString(double) */ public String toString() { return toString(value); } /** * Return the value of this <code>Double</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>Double</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>Double</code> as an <code>int</code>. * * @return the int value */ public int intValue() { return (int) value; } /** * Return the value of this <code>Double</code> as a <code>long</code>. * * @return the long value */ public long longValue() { return (long) value; } /** * Return the value of this <code>Double</code> as a <code>float</code>. * * @return the float value */ public float floatValue() { return (float) value; } /** * Return the value of this <code>Double</code>. * * @return the double value */ public double doubleValue() { return value; } /** * Return a hashcode representing this Object. <code>Double</code>'s hash * code is calculated by:<br> * <code>long v = Double.doubleToLongBits(doubleValue());<br> * int hash = (int)(v^(v>>32))</code>. * * @return this Object's hash code * @see #doubleToLongBits(double) */ public int hashCode() { long v = doubleToLongBits(value); return (int) (v ^ (v >>> 32)); } /** * Returns <code>true</code> if <code>obj</code> is an instance of * <code>Double</code> and represents the same double value. Unlike comparing * two doubles with <code>==</code>, this treats two instances of * <code>Double.NaN</code> as equal, but treats <code>0.0</code> and * <code>-0.0</code> as unequal. * * <p>Note that <code>d1.equals(d2)</code> is identical to * <code>doubleToLongBits(d1.doubleValue()) == * doubleToLongBits(d2.doubleValue())</code>. * * @param obj the object to compare * @return whether the objects are semantically equal */ public boolean equals(Object obj) { if (! (obj instanceof Double)) return false; double d = ((Double) 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 == d) return (value != 0) || (1 / value == 1 / d); return isNaN(value) && isNaN(d); } /** * Convert the double to the IEEE 754 floating-point "double format" bit * layout. Bit 63 (the most significant) is the sign bit, bits 62-52 * (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 * (masked by 0x000fffffffffffffL) are the mantissa. This function * collapses all versions of NaN to 0x7ff8000000000000L. The result of this * function can be used as the argument to * <code>Double.longBitsToDouble(long)</code> to obtain the original * <code>double</code> value. * * @param value the <code>double</code> to convert * @return the bits of the <code>double</code> * @see #longBitsToDouble(long) */ public static long doubleToLongBits(double value) { return VMDouble.doubleToLongBits(value); } /** * Convert the double to the IEEE 754 floating-point "double format" bit * layout. Bit 63 (the most significant) is the sign bit, bits 62-52 * (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 * (masked by 0x000fffffffffffffL) 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>Double.longBitsToDouble(long)</code> to obtain the original * <code>double</code> value. * * @param value the <code>double</code> to convert * @return the bits of the <code>double</code> * @see #longBitsToDouble(long) */ public static long doubleToRawLongBits(double value) { return VMDouble.doubleToRawLongBits(value); } /** * Convert the argument in IEEE 754 floating-point "double format" bit * layout to the corresponding float. Bit 63 (the most significant) is the * sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the * exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa. * This function leaves NaN alone, so that you can recover the bit pattern * with <code>Double.doubleToRawLongBits(double)</code>. * * @param bits the bits to convert * @return the <code>double</code> represented by the bits * @see #doubleToLongBits(double) * @see #doubleToRawLongBits(double) */ public static double longBitsToDouble(long bits) { return VMDouble.longBitsToDouble(bits); } /** * Compare two Doubles numerically by comparing their <code>double</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 doubles, including <code>POSITIVE_INFINITY</code>, and positive * zero is considered greater than negative zero. * * @param d the Double to compare * @return the comparison * @since 1.2 */ public int compareTo(Double d) { return compare(value, d.value); } /** * Behaves like <code>compareTo(Double)</code> unless the Object * is not an <code>Double</code>. * * @param o the object to compare * @return the comparison * @throws ClassCastException if the argument is not a <code>Double</code> * @see #compareTo(Double) * @see Comparable * @since 1.2 */ public int compareTo(Object o) { return compare(value, ((Double) o).value); } /** * Behaves like <code>new Double(x).compareTo(new Double(y))</code>; in * other words this compares two doubles, special casing NaN and zero, * without the overhead of objects. * * @param x the first double to compare * @param y the second double to compare * @return the comparison * @since 1.4 */ public static int compare(double x, double y) { if (isNaN(x)) return isNaN(y) ? 0 : 1; if (isNaN(y)) return -1; // recall that 0.0 == -0.0, so we convert to infinites 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 + -