26 package java.lang;
27
28 import sun.misc.FloatingDecimal;
29 import sun.misc.DoubleConsts;
30
31 /**
32 * The {@code Double} class wraps a value of the primitive type
33 * {@code double} in an object. An object of type
34 * {@code Double} contains a single field whose type is
35 * {@code double}.
36 *
37 * <p>In addition, this class provides several methods for converting a
38 * {@code double} to a {@code String} and a
39 * {@code String} to a {@code double}, as well as other
40 * constants and methods useful when dealing with a
41 * {@code double}.
42 *
43 * @author Lee Boynton
44 * @author Arthur van Hoff
45 * @author Joseph D. Darcy
46 * @since JDK1.0
47 */
48 public final class Double extends Number implements Comparable<Double> {
49 /**
50 * A constant holding the positive infinity of type
51 * {@code double}. It is equal to the value returned by
52 * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
53 */
54 public static final double POSITIVE_INFINITY = 1.0 / 0.0;
55
56 /**
57 * A constant holding the negative infinity of type
58 * {@code double}. It is equal to the value returned by
59 * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
60 */
61 public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
62
63 /**
64 * A constant holding a Not-a-Number (NaN) value of type
65 * {@code double}. It is equivalent to the value returned by
66 * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
115 public static final int MIN_EXPONENT = -1022;
116
117 /**
118 * The number of bits used to represent a {@code double} value.
119 *
120 * @since 1.5
121 */
122 public static final int SIZE = 64;
123
124 /**
125 * The number of bytes used to represent a {@code double} value.
126 *
127 * @since 1.8
128 */
129 public static final int BYTES = SIZE / Byte.SIZE;
130
131 /**
132 * The {@code Class} instance representing the primitive type
133 * {@code double}.
134 *
135 * @since JDK1.1
136 */
137 @SuppressWarnings("unchecked")
138 public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
139
140 /**
141 * Returns a string representation of the {@code double}
142 * argument. All characters mentioned below are ASCII characters.
143 * <ul>
144 * <li>If the argument is NaN, the result is the string
145 * "{@code NaN}".
146 * <li>Otherwise, the result is a string that represents the sign and
147 * magnitude (absolute value) of the argument. If the sign is negative,
148 * the first character of the result is '{@code -}'
149 * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
150 * appears in the result. As for the magnitude <i>m</i>:
151 * <ul>
152 * <li>If <i>m</i> is infinity, it is represented by the characters
153 * {@code "Infinity"}; thus, positive infinity produces the result
154 * {@code "Infinity"} and negative infinity produces the result
155 * {@code "-Infinity"}.
633 /**
634 * Returns a string representation of this {@code Double} object.
635 * The primitive {@code double} value represented by this
636 * object is converted to a string exactly as if by the method
637 * {@code toString} of one argument.
638 *
639 * @return a {@code String} representation of this object.
640 * @see java.lang.Double#toString(double)
641 */
642 public String toString() {
643 return toString(value);
644 }
645
646 /**
647 * Returns the value of this {@code Double} as a {@code byte}
648 * after a narrowing primitive conversion.
649 *
650 * @return the {@code double} value represented by this object
651 * converted to type {@code byte}
652 * @jls 5.1.3 Narrowing Primitive Conversions
653 * @since JDK1.1
654 */
655 public byte byteValue() {
656 return (byte)value;
657 }
658
659 /**
660 * Returns the value of this {@code Double} as a {@code short}
661 * after a narrowing primitive conversion.
662 *
663 * @return the {@code double} value represented by this object
664 * converted to type {@code short}
665 * @jls 5.1.3 Narrowing Primitive Conversions
666 * @since JDK1.1
667 */
668 public short shortValue() {
669 return (short)value;
670 }
671
672 /**
673 * Returns the value of this {@code Double} as an {@code int}
674 * after a narrowing primitive conversion.
675 * @jls 5.1.3 Narrowing Primitive Conversions
676 *
677 * @return the {@code double} value represented by this object
678 * converted to type {@code int}
679 */
680 public int intValue() {
681 return (int)value;
682 }
683
684 /**
685 * Returns the value of this {@code Double} as a {@code long}
686 * after a narrowing primitive conversion.
687 *
688 * @return the {@code double} value represented by this object
689 * converted to type {@code long}
690 * @jls 5.1.3 Narrowing Primitive Conversions
691 */
692 public long longValue() {
693 return (long)value;
694 }
695
696 /**
697 * Returns the value of this {@code Double} as a {@code float}
698 * after a narrowing primitive conversion.
699 *
700 * @return the {@code double} value represented by this object
701 * converted to type {@code float}
702 * @jls 5.1.3 Narrowing Primitive Conversions
703 * @since JDK1.0
704 */
705 public float floatValue() {
706 return (float)value;
707 }
708
709 /**
710 * Returns the {@code double} value of this {@code Double} object.
711 *
712 * @return the {@code double} value represented by this object
713 */
714 public double doubleValue() {
715 return value;
716 }
717
718 /**
719 * Returns a hash code for this {@code Double} object. The
720 * result is the exclusive OR of the two halves of the
721 * {@code long} integer bit representation, exactly as
722 * produced by the method {@link #doubleToLongBits(double)}, of
723 * the primitive {@code double} value represented by this
|
26 package java.lang;
27
28 import sun.misc.FloatingDecimal;
29 import sun.misc.DoubleConsts;
30
31 /**
32 * The {@code Double} class wraps a value of the primitive type
33 * {@code double} in an object. An object of type
34 * {@code Double} contains a single field whose type is
35 * {@code double}.
36 *
37 * <p>In addition, this class provides several methods for converting a
38 * {@code double} to a {@code String} and a
39 * {@code String} to a {@code double}, as well as other
40 * constants and methods useful when dealing with a
41 * {@code double}.
42 *
43 * @author Lee Boynton
44 * @author Arthur van Hoff
45 * @author Joseph D. Darcy
46 * @since 1.0
47 */
48 public final class Double extends Number implements Comparable<Double> {
49 /**
50 * A constant holding the positive infinity of type
51 * {@code double}. It is equal to the value returned by
52 * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
53 */
54 public static final double POSITIVE_INFINITY = 1.0 / 0.0;
55
56 /**
57 * A constant holding the negative infinity of type
58 * {@code double}. It is equal to the value returned by
59 * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
60 */
61 public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
62
63 /**
64 * A constant holding a Not-a-Number (NaN) value of type
65 * {@code double}. It is equivalent to the value returned by
66 * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
115 public static final int MIN_EXPONENT = -1022;
116
117 /**
118 * The number of bits used to represent a {@code double} value.
119 *
120 * @since 1.5
121 */
122 public static final int SIZE = 64;
123
124 /**
125 * The number of bytes used to represent a {@code double} value.
126 *
127 * @since 1.8
128 */
129 public static final int BYTES = SIZE / Byte.SIZE;
130
131 /**
132 * The {@code Class} instance representing the primitive type
133 * {@code double}.
134 *
135 * @since 1.1
136 */
137 @SuppressWarnings("unchecked")
138 public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
139
140 /**
141 * Returns a string representation of the {@code double}
142 * argument. All characters mentioned below are ASCII characters.
143 * <ul>
144 * <li>If the argument is NaN, the result is the string
145 * "{@code NaN}".
146 * <li>Otherwise, the result is a string that represents the sign and
147 * magnitude (absolute value) of the argument. If the sign is negative,
148 * the first character of the result is '{@code -}'
149 * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
150 * appears in the result. As for the magnitude <i>m</i>:
151 * <ul>
152 * <li>If <i>m</i> is infinity, it is represented by the characters
153 * {@code "Infinity"}; thus, positive infinity produces the result
154 * {@code "Infinity"} and negative infinity produces the result
155 * {@code "-Infinity"}.
633 /**
634 * Returns a string representation of this {@code Double} object.
635 * The primitive {@code double} value represented by this
636 * object is converted to a string exactly as if by the method
637 * {@code toString} of one argument.
638 *
639 * @return a {@code String} representation of this object.
640 * @see java.lang.Double#toString(double)
641 */
642 public String toString() {
643 return toString(value);
644 }
645
646 /**
647 * Returns the value of this {@code Double} as a {@code byte}
648 * after a narrowing primitive conversion.
649 *
650 * @return the {@code double} value represented by this object
651 * converted to type {@code byte}
652 * @jls 5.1.3 Narrowing Primitive Conversions
653 * @since 1.1
654 */
655 public byte byteValue() {
656 return (byte)value;
657 }
658
659 /**
660 * Returns the value of this {@code Double} as a {@code short}
661 * after a narrowing primitive conversion.
662 *
663 * @return the {@code double} value represented by this object
664 * converted to type {@code short}
665 * @jls 5.1.3 Narrowing Primitive Conversions
666 * @since 1.1
667 */
668 public short shortValue() {
669 return (short)value;
670 }
671
672 /**
673 * Returns the value of this {@code Double} as an {@code int}
674 * after a narrowing primitive conversion.
675 * @jls 5.1.3 Narrowing Primitive Conversions
676 *
677 * @return the {@code double} value represented by this object
678 * converted to type {@code int}
679 */
680 public int intValue() {
681 return (int)value;
682 }
683
684 /**
685 * Returns the value of this {@code Double} as a {@code long}
686 * after a narrowing primitive conversion.
687 *
688 * @return the {@code double} value represented by this object
689 * converted to type {@code long}
690 * @jls 5.1.3 Narrowing Primitive Conversions
691 */
692 public long longValue() {
693 return (long)value;
694 }
695
696 /**
697 * Returns the value of this {@code Double} as a {@code float}
698 * after a narrowing primitive conversion.
699 *
700 * @return the {@code double} value represented by this object
701 * converted to type {@code float}
702 * @jls 5.1.3 Narrowing Primitive Conversions
703 * @since 1.0
704 */
705 public float floatValue() {
706 return (float)value;
707 }
708
709 /**
710 * Returns the {@code double} value of this {@code Double} object.
711 *
712 * @return the {@code double} value represented by this object
713 */
714 public double doubleValue() {
715 return value;
716 }
717
718 /**
719 * Returns a hash code for this {@code Double} object. The
720 * result is the exclusive OR of the two halves of the
721 * {@code long} integer bit representation, exactly as
722 * produced by the method {@link #doubleToLongBits(double)}, of
723 * the primitive {@code double} value represented by this
|