< prev index next >

src/java.base/share/classes/java/lang/Double.java

Print this page
rev 52786 : 8210031: implementation for JVM Constants API


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 





  28 import jdk.internal.math.FloatingDecimal;
  29 import jdk.internal.math.DoubleConsts;
  30 import jdk.internal.HotSpotIntrinsicCandidate;
  31 
  32 /**
  33  * The {@code Double} class wraps a value of the primitive type
  34  * {@code double} in an object. An object of type
  35  * {@code Double} contains a single field whose type is
  36  * {@code double}.
  37  *
  38  * <p>In addition, this class provides several methods for converting a
  39  * {@code double} to a {@code String} and a
  40  * {@code String} to a {@code double}, as well as other
  41  * constants and methods useful when dealing with a
  42  * {@code double}.
  43  *
  44  * @author  Lee Boynton
  45  * @author  Arthur van Hoff
  46  * @author  Joseph D. Darcy
  47  * @since 1.0
  48  */
  49 public final class Double extends Number implements Comparable<Double> {

  50     /**
  51      * A constant holding the positive infinity of type
  52      * {@code double}. It is equal to the value returned by
  53      * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  54      */
  55     public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  56 
  57     /**
  58      * A constant holding the negative infinity of type
  59      * {@code double}. It is equal to the value returned by
  60      * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  61      */
  62     public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  63 
  64     /**
  65      * A constant holding a Not-a-Number (NaN) value of type
  66      * {@code double}. It is equivalent to the value returned by
  67      * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  68      */
  69     public static final double NaN = 0.0d / 0.0;


1051      * @return the greater of {@code a} and {@code b}
1052      * @see java.util.function.BinaryOperator
1053      * @since 1.8
1054      */
1055     public static double max(double a, double b) {
1056         return Math.max(a, b);
1057     }
1058 
1059     /**
1060      * Returns the smaller of two {@code double} values
1061      * as if by calling {@link Math#min(double, double) Math.min}.
1062      *
1063      * @param a the first operand
1064      * @param b the second operand
1065      * @return the smaller of {@code a} and {@code b}.
1066      * @see java.util.function.BinaryOperator
1067      * @since 1.8
1068      */
1069     public static double min(double a, double b) {
1070         return Math.min(a, b);

























1071     }
1072 
1073     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1074     private static final long serialVersionUID = -9172774392245257468L;
1075 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.constant.Constable;
  30 import java.lang.constant.ConstantDesc;
  31 import java.util.Optional;
  32 
  33 import jdk.internal.math.FloatingDecimal;
  34 import jdk.internal.math.DoubleConsts;
  35 import jdk.internal.HotSpotIntrinsicCandidate;
  36 
  37 /**
  38  * The {@code Double} class wraps a value of the primitive type
  39  * {@code double} in an object. An object of type
  40  * {@code Double} contains a single field whose type is
  41  * {@code double}.
  42  *
  43  * <p>In addition, this class provides several methods for converting a
  44  * {@code double} to a {@code String} and a
  45  * {@code String} to a {@code double}, as well as other
  46  * constants and methods useful when dealing with a
  47  * {@code double}.
  48  *
  49  * @author  Lee Boynton
  50  * @author  Arthur van Hoff
  51  * @author  Joseph D. Darcy
  52  * @since 1.0
  53  */
  54 public final class Double extends Number
  55         implements Comparable<Double>, ConstantDesc, Constable {
  56     /**
  57      * A constant holding the positive infinity of type
  58      * {@code double}. It is equal to the value returned by
  59      * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  60      */
  61     public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  62 
  63     /**
  64      * A constant holding the negative infinity of type
  65      * {@code double}. It is equal to the value returned by
  66      * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  67      */
  68     public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  69 
  70     /**
  71      * A constant holding a Not-a-Number (NaN) value of type
  72      * {@code double}. It is equivalent to the value returned by
  73      * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  74      */
  75     public static final double NaN = 0.0d / 0.0;


1057      * @return the greater of {@code a} and {@code b}
1058      * @see java.util.function.BinaryOperator
1059      * @since 1.8
1060      */
1061     public static double max(double a, double b) {
1062         return Math.max(a, b);
1063     }
1064 
1065     /**
1066      * Returns the smaller of two {@code double} values
1067      * as if by calling {@link Math#min(double, double) Math.min}.
1068      *
1069      * @param a the first operand
1070      * @param b the second operand
1071      * @return the smaller of {@code a} and {@code b}.
1072      * @see java.util.function.BinaryOperator
1073      * @since 1.8
1074      */
1075     public static double min(double a, double b) {
1076         return Math.min(a, b);
1077     }
1078 
1079     /**
1080      * Returns a nominal descriptor for this instance, which is the instance
1081      * itself.
1082      *
1083      * @return an {@link Optional} describing the {@linkplain Double} instance
1084      * @since 12
1085      */
1086     @Override
1087     public Optional<Double> describeConstable() {
1088         return Optional.of(this);
1089     }
1090 
1091     /**
1092      * Resolve this instance as a {@link ConstantDesc}, the result of which is
1093      * the instance itself.
1094      *
1095      * @param lookup ignored
1096      * @return the {@linkplain Double} instance
1097      * @since 12
1098      */
1099     @Override
1100     public Double resolveConstantDesc(MethodHandles.Lookup lookup) {
1101         return this;
1102     }
1103 
1104     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1105     private static final long serialVersionUID = -9172774392245257468L;
1106 }
< prev index next >