author | smarks |
Mon, 18 Apr 2016 14:10:14 -0700 | |
changeset 37521 | b6e0f285c998 |
parent 35979 | 4462913d471a |
child 45124 | 144479e89cdb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35979
4462913d471a
8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents:
34781
diff
changeset
|
2 |
* Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
34781
479b1724ab80
8145990: Move sun.misc math support classes to jdk.internal.math
chegar
parents:
31671
diff
changeset
|
28 |
import jdk.internal.math.FloatingDecimal; |
479b1724ab80
8145990: Move sun.misc math support classes to jdk.internal.math
chegar
parents:
31671
diff
changeset
|
29 |
import jdk.internal.math.DoubleConsts; |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
30 |
import jdk.internal.HotSpotIntrinsicCandidate; |
2 | 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 |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22634
diff
changeset
|
47 |
* @since 1.0 |
2 | 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; |
|
70 |
||
71 |
/** |
|
72 |
* A constant holding the largest positive finite value of type |
|
73 |
* {@code double}, |
|
74 |
* (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to |
|
75 |
* the hexadecimal floating-point literal |
|
76 |
* {@code 0x1.fffffffffffffP+1023} and also equal to |
|
77 |
* {@code Double.longBitsToDouble(0x7fefffffffffffffL)}. |
|
78 |
*/ |
|
79 |
public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308 |
|
80 |
||
81 |
/** |
|
82 |
* A constant holding the smallest positive normal value of type |
|
83 |
* {@code double}, 2<sup>-1022</sup>. It is equal to the |
|
84 |
* hexadecimal floating-point literal {@code 0x1.0p-1022} and also |
|
85 |
* equal to {@code Double.longBitsToDouble(0x0010000000000000L)}. |
|
86 |
* |
|
87 |
* @since 1.6 |
|
88 |
*/ |
|
89 |
public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308 |
|
90 |
||
91 |
/** |
|
92 |
* A constant holding the smallest positive nonzero value of type |
|
93 |
* {@code double}, 2<sup>-1074</sup>. It is equal to the |
|
94 |
* hexadecimal floating-point literal |
|
95 |
* {@code 0x0.0000000000001P-1022} and also equal to |
|
96 |
* {@code Double.longBitsToDouble(0x1L)}. |
|
97 |
*/ |
|
98 |
public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324 |
|
99 |
||
100 |
/** |
|
101 |
* Maximum exponent a finite {@code double} variable may have. |
|
102 |
* It is equal to the value returned by |
|
103 |
* {@code Math.getExponent(Double.MAX_VALUE)}. |
|
104 |
* |
|
105 |
* @since 1.6 |
|
106 |
*/ |
|
107 |
public static final int MAX_EXPONENT = 1023; |
|
108 |
||
109 |
/** |
|
110 |
* Minimum exponent a normalized {@code double} variable may |
|
111 |
* have. It is equal to the value returned by |
|
112 |
* {@code Math.getExponent(Double.MIN_NORMAL)}. |
|
113 |
* |
|
114 |
* @since 1.6 |
|
115 |
*/ |
|
116 |
public static final int MIN_EXPONENT = -1022; |
|
117 |
||
118 |
/** |
|
119 |
* The number of bits used to represent a {@code double} value. |
|
120 |
* |
|
121 |
* @since 1.5 |
|
122 |
*/ |
|
123 |
public static final int SIZE = 64; |
|
124 |
||
125 |
/** |
|
14507
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
126 |
* The number of bytes used to represent a {@code double} value. |
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
127 |
* |
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
128 |
* @since 1.8 |
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
129 |
*/ |
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
130 |
public static final int BYTES = SIZE / Byte.SIZE; |
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
131 |
|
066419d1e732
7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents:
14503
diff
changeset
|
132 |
/** |
2 | 133 |
* The {@code Class} instance representing the primitive type |
134 |
* {@code double}. |
|
135 |
* |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22634
diff
changeset
|
136 |
* @since 1.1 |
2 | 137 |
*/ |
11275 | 138 |
@SuppressWarnings("unchecked") |
2 | 139 |
public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double"); |
140 |
||
141 |
/** |
|
142 |
* Returns a string representation of the {@code double} |
|
143 |
* argument. All characters mentioned below are ASCII characters. |
|
144 |
* <ul> |
|
145 |
* <li>If the argument is NaN, the result is the string |
|
146 |
* "{@code NaN}". |
|
147 |
* <li>Otherwise, the result is a string that represents the sign and |
|
148 |
* magnitude (absolute value) of the argument. If the sign is negative, |
|
149 |
* the first character of the result is '{@code -}' |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
11275
diff
changeset
|
150 |
* ({@code '\u005Cu002D'}); if the sign is positive, no sign character |
2 | 151 |
* appears in the result. As for the magnitude <i>m</i>: |
152 |
* <ul> |
|
153 |
* <li>If <i>m</i> is infinity, it is represented by the characters |
|
154 |
* {@code "Infinity"}; thus, positive infinity produces the result |
|
155 |
* {@code "Infinity"} and negative infinity produces the result |
|
156 |
* {@code "-Infinity"}. |
|
157 |
* |
|
158 |
* <li>If <i>m</i> is zero, it is represented by the characters |
|
159 |
* {@code "0.0"}; thus, negative zero produces the result |
|
160 |
* {@code "-0.0"} and positive zero produces the result |
|
161 |
* {@code "0.0"}. |
|
162 |
* |
|
163 |
* <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less |
|
164 |
* than 10<sup>7</sup>, then it is represented as the integer part of |
|
165 |
* <i>m</i>, in decimal form with no leading zeroes, followed by |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
11275
diff
changeset
|
166 |
* '{@code .}' ({@code '\u005Cu002E'}), followed by one or |
2 | 167 |
* more decimal digits representing the fractional part of <i>m</i>. |
168 |
* |
|
169 |
* <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or |
|
170 |
* equal to 10<sup>7</sup>, then it is represented in so-called |
|
171 |
* "computerized scientific notation." Let <i>n</i> be the unique |
|
172 |
* integer such that 10<sup><i>n</i></sup> ≤ <i>m</i> {@literal <} |
|
173 |
* 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the |
|
174 |
* mathematically exact quotient of <i>m</i> and |
|
175 |
* 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10. The |
|
176 |
* magnitude is then represented as the integer part of <i>a</i>, |
|
177 |
* as a single decimal digit, followed by '{@code .}' |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
11275
diff
changeset
|
178 |
* ({@code '\u005Cu002E'}), followed by decimal digits |
2 | 179 |
* representing the fractional part of <i>a</i>, followed by the |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
11275
diff
changeset
|
180 |
* letter '{@code E}' ({@code '\u005Cu0045'}), followed |
2 | 181 |
* by a representation of <i>n</i> as a decimal integer, as |
182 |
* produced by the method {@link Integer#toString(int)}. |
|
183 |
* </ul> |
|
184 |
* </ul> |
|
185 |
* How many digits must be printed for the fractional part of |
|
186 |
* <i>m</i> or <i>a</i>? There must be at least one digit to represent |
|
187 |
* the fractional part, and beyond that as many, but only as many, more |
|
188 |
* digits as are needed to uniquely distinguish the argument value from |
|
189 |
* adjacent values of type {@code double}. That is, suppose that |
|
190 |
* <i>x</i> is the exact mathematical value represented by the decimal |
|
191 |
* representation produced by this method for a finite nonzero argument |
|
192 |
* <i>d</i>. Then <i>d</i> must be the {@code double} value nearest |
|
193 |
* to <i>x</i>; or if two {@code double} values are equally close |
|
194 |
* to <i>x</i>, then <i>d</i> must be one of them and the least |
|
195 |
* significant bit of the significand of <i>d</i> must be {@code 0}. |
|
196 |
* |
|
197 |
* <p>To create localized string representations of a floating-point |
|
198 |
* value, use subclasses of {@link java.text.NumberFormat}. |
|
199 |
* |
|
200 |
* @param d the {@code double} to be converted. |
|
201 |
* @return a string representation of the argument. |
|
202 |
*/ |
|
203 |
public static String toString(double d) { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
15525
diff
changeset
|
204 |
return FloatingDecimal.toJavaFormatString(d); |
2 | 205 |
} |
206 |
||
207 |
/** |
|
208 |
* Returns a hexadecimal string representation of the |
|
209 |
* {@code double} argument. All characters mentioned below |
|
210 |
* are ASCII characters. |
|
211 |
* |
|
212 |
* <ul> |
|
213 |
* <li>If the argument is NaN, the result is the string |
|
214 |
* "{@code NaN}". |
|
215 |
* <li>Otherwise, the result is a string that represents the sign |
|
216 |
* and magnitude of the argument. If the sign is negative, the |
|
217 |
* first character of the result is '{@code -}' |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
11275
diff
changeset
|
218 |
* ({@code '\u005Cu002D'}); if the sign is positive, no sign |
2 | 219 |
* character appears in the result. As for the magnitude <i>m</i>: |
220 |
* |
|
221 |
* <ul> |
|
222 |
* <li>If <i>m</i> is infinity, it is represented by the string |
|
223 |
* {@code "Infinity"}; thus, positive infinity produces the |
|
224 |
* result {@code "Infinity"} and negative infinity produces |
|
225 |
* the result {@code "-Infinity"}. |
|
226 |
* |
|
227 |
* <li>If <i>m</i> is zero, it is represented by the string |
|
228 |
* {@code "0x0.0p0"}; thus, negative zero produces the result |
|
229 |
* {@code "-0x0.0p0"} and positive zero produces the result |
|
230 |
* {@code "0x0.0p0"}. |
|
231 |
* |
|
232 |
* <li>If <i>m</i> is a {@code double} value with a |
|
233 |
* normalized representation, substrings are used to represent the |
|
234 |
* significand and exponent fields. The significand is |
|
235 |
* represented by the characters {@code "0x1."} |
|
236 |
* followed by a lowercase hexadecimal representation of the rest |
|
237 |
* of the significand as a fraction. Trailing zeros in the |
|
238 |
* hexadecimal representation are removed unless all the digits |
|
239 |
* are zero, in which case a single zero is used. Next, the |
|
240 |
* exponent is represented by {@code "p"} followed |
|
241 |
* by a decimal string of the unbiased exponent as if produced by |
|
242 |
* a call to {@link Integer#toString(int) Integer.toString} on the |
|
243 |
* exponent value. |
|
244 |
* |
|
245 |
* <li>If <i>m</i> is a {@code double} value with a subnormal |
|
246 |
* representation, the significand is represented by the |
|
247 |
* characters {@code "0x0."} followed by a |
|
248 |
* hexadecimal representation of the rest of the significand as a |
|
249 |
* fraction. Trailing zeros in the hexadecimal representation are |
|
250 |
* removed. Next, the exponent is represented by |
|
251 |
* {@code "p-1022"}. Note that there must be at |
|
252 |
* least one nonzero digit in a subnormal significand. |
|
253 |
* |
|
254 |
* </ul> |
|
255 |
* |
|
256 |
* </ul> |
|
257 |
* |
|
258 |
* <table border> |
|
18776 | 259 |
* <caption>Examples</caption> |
2 | 260 |
* <tr><th>Floating-point Value</th><th>Hexadecimal String</th> |
261 |
* <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td> |
|
262 |
* <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td> |
|
263 |
* <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td> |
|
264 |
* <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td> |
|
265 |
* <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td> |
|
266 |
* <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td> |
|
267 |
* <tr><td>{@code Double.MAX_VALUE}</td> |
|
268 |
* <td>{@code 0x1.fffffffffffffp1023}</td> |
|
269 |
* <tr><td>{@code Minimum Normal Value}</td> |
|
270 |
* <td>{@code 0x1.0p-1022}</td> |
|
271 |
* <tr><td>{@code Maximum Subnormal Value}</td> |
|
272 |
* <td>{@code 0x0.fffffffffffffp-1022}</td> |
|
273 |
* <tr><td>{@code Double.MIN_VALUE}</td> |
|
274 |
* <td>{@code 0x0.0000000000001p-1022}</td> |
|
275 |
* </table> |
|
276 |
* @param d the {@code double} to be converted. |
|
277 |
* @return a hex string representation of the argument. |
|
278 |
* @since 1.5 |
|
279 |
* @author Joseph D. Darcy |
|
280 |
*/ |
|
281 |
public static String toHexString(double d) { |
|
282 |
/* |
|
283 |
* Modeled after the "a" conversion specifier in C99, section |
|
284 |
* 7.19.6.1; however, the output of this method is more |
|
285 |
* tightly specified. |
|
286 |
*/ |
|
10608 | 287 |
if (!isFinite(d) ) |
2 | 288 |
// For infinity and NaN, use the decimal output. |
289 |
return Double.toString(d); |
|
290 |
else { |
|
291 |
// Initialized to maximum size of output. |
|
15525
0308cc37489b
6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
darcy
parents:
15311
diff
changeset
|
292 |
StringBuilder answer = new StringBuilder(24); |
2 | 293 |
|
10598
efd29b4b3e67
7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents:
10067
diff
changeset
|
294 |
if (Math.copySign(1.0, d) == -1.0) // value is negative, |
2 | 295 |
answer.append("-"); // so append sign info |
296 |
||
297 |
answer.append("0x"); |
|
298 |
||
299 |
d = Math.abs(d); |
|
300 |
||
301 |
if(d == 0.0) { |
|
302 |
answer.append("0.0p0"); |
|
15525
0308cc37489b
6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
darcy
parents:
15311
diff
changeset
|
303 |
} else { |
35979
4462913d471a
8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents:
34781
diff
changeset
|
304 |
boolean subnormal = (d < Double.MIN_NORMAL); |
2 | 305 |
|
306 |
// Isolate significand bits and OR in a high-order bit |
|
307 |
// so that the string representation has a known |
|
308 |
// length. |
|
309 |
long signifBits = (Double.doubleToLongBits(d) |
|
310 |
& DoubleConsts.SIGNIF_BIT_MASK) | |
|
311 |
0x1000000000000000L; |
|
312 |
||
313 |
// Subnormal values have a 0 implicit bit; normal |
|
314 |
// values have a 1 implicit bit. |
|
315 |
answer.append(subnormal ? "0." : "1."); |
|
316 |
||
317 |
// Isolate the low-order 13 digits of the hex |
|
318 |
// representation. If all the digits are zero, |
|
319 |
// replace with a single 0; otherwise, remove all |
|
320 |
// trailing zeros. |
|
321 |
String signif = Long.toHexString(signifBits).substring(3,16); |
|
322 |
answer.append(signif.equals("0000000000000") ? // 13 zeros |
|
323 |
"0": |
|
324 |
signif.replaceFirst("0{1,12}$", "")); |
|
325 |
||
15525
0308cc37489b
6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
darcy
parents:
15311
diff
changeset
|
326 |
answer.append('p'); |
2 | 327 |
// If the value is subnormal, use the E_min exponent |
328 |
// value for double; otherwise, extract and report d's |
|
329 |
// exponent (the representation of a subnormal uses |
|
330 |
// E_min -1). |
|
15525
0308cc37489b
6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
darcy
parents:
15311
diff
changeset
|
331 |
answer.append(subnormal ? |
35979
4462913d471a
8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents:
34781
diff
changeset
|
332 |
Double.MIN_EXPONENT: |
15525
0308cc37489b
6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
darcy
parents:
15311
diff
changeset
|
333 |
Math.getExponent(d)); |
2 | 334 |
} |
335 |
return answer.toString(); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
/** |
|
340 |
* Returns a {@code Double} object holding the |
|
341 |
* {@code double} value represented by the argument string |
|
342 |
* {@code s}. |
|
343 |
* |
|
344 |
* <p>If {@code s} is {@code null}, then a |
|
345 |
* {@code NullPointerException} is thrown. |
|
346 |
* |
|
347 |
* <p>Leading and trailing whitespace characters in {@code s} |
|
348 |
* are ignored. Whitespace is removed as if by the {@link |
|
349 |
* String#trim} method; that is, both ASCII space and control |
|
350 |
* characters are removed. The rest of {@code s} should |
|
351 |
* constitute a <i>FloatValue</i> as described by the lexical |
|
352 |
* syntax rules: |
|
353 |
* |
|
354 |
* <blockquote> |
|
355 |
* <dl> |
|
356 |
* <dt><i>FloatValue:</i> |
|
357 |
* <dd><i>Sign<sub>opt</sub></i> {@code NaN} |
|
358 |
* <dd><i>Sign<sub>opt</sub></i> {@code Infinity} |
|
359 |
* <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i> |
|
360 |
* <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i> |
|
361 |
* <dd><i>SignedInteger</i> |
|
362 |
* </dl> |
|
363 |
* |
|
364 |
* <dl> |
|
365 |
* <dt><i>HexFloatingPointLiteral</i>: |
|
366 |
* <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i> |
|
367 |
* </dl> |
|
368 |
* |
|
369 |
* <dl> |
|
370 |
* <dt><i>HexSignificand:</i> |
|
371 |
* <dd><i>HexNumeral</i> |
|
372 |
* <dd><i>HexNumeral</i> {@code .} |
|
373 |
* <dd>{@code 0x} <i>HexDigits<sub>opt</sub> |
|
374 |
* </i>{@code .}<i> HexDigits</i> |
|
375 |
* <dd>{@code 0X}<i> HexDigits<sub>opt</sub> |
|
376 |
* </i>{@code .} <i>HexDigits</i> |
|
377 |
* </dl> |
|
378 |
* |
|
379 |
* <dl> |
|
380 |
* <dt><i>BinaryExponent:</i> |
|
381 |
* <dd><i>BinaryExponentIndicator SignedInteger</i> |
|
382 |
* </dl> |
|
383 |
* |
|
384 |
* <dl> |
|
385 |
* <dt><i>BinaryExponentIndicator:</i> |
|
386 |
* <dd>{@code p} |
|
387 |
* <dd>{@code P} |
|
388 |
* </dl> |
|
389 |
* |
|
390 |
* </blockquote> |
|
391 |
* |
|
392 |
* where <i>Sign</i>, <i>FloatingPointLiteral</i>, |
|
393 |
* <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and |
|
394 |
* <i>FloatTypeSuffix</i> are as defined in the lexical structure |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7517
diff
changeset
|
395 |
* sections of |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7517
diff
changeset
|
396 |
* <cite>The Java™ Language Specification</cite>, |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7517
diff
changeset
|
397 |
* except that underscores are not accepted between digits. |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7517
diff
changeset
|
398 |
* If {@code s} does not have the form of |
2 | 399 |
* a <i>FloatValue</i>, then a {@code NumberFormatException} |
400 |
* is thrown. Otherwise, {@code s} is regarded as |
|
401 |
* representing an exact decimal value in the usual |
|
402 |
* "computerized scientific notation" or as an exact |
|
403 |
* hexadecimal value; this exact numerical value is then |
|
404 |
* conceptually converted to an "infinitely precise" |
|
405 |
* binary value that is then rounded to type {@code double} |
|
406 |
* by the usual round-to-nearest rule of IEEE 754 floating-point |
|
407 |
* arithmetic, which includes preserving the sign of a zero |
|
1824
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
408 |
* value. |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
409 |
* |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
410 |
* Note that the round-to-nearest rule also implies overflow and |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
411 |
* underflow behaviour; if the exact value of {@code s} is large |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
412 |
* enough in magnitude (greater than or equal to ({@link |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
413 |
* #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2), |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
414 |
* rounding to {@code double} will result in an infinity and if the |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
415 |
* exact value of {@code s} is small enough in magnitude (less |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
416 |
* than or equal to {@link #MIN_VALUE}/2), rounding to float will |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
417 |
* result in a zero. |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
418 |
* |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
419 |
* Finally, after rounding a {@code Double} object representing |
7a685390c6ab
6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents:
2
diff
changeset
|
420 |
* this {@code double} value is returned. |
2 | 421 |
* |
422 |
* <p> To interpret localized string representations of a |
|
423 |
* floating-point value, use subclasses of {@link |
|
424 |
* java.text.NumberFormat}. |
|
425 |
* |
|
426 |
* <p>Note that trailing format specifiers, specifiers that |
|
427 |
* determine the type of a floating-point literal |
|
428 |
* ({@code 1.0f} is a {@code float} value; |
|
429 |
* {@code 1.0d} is a {@code double} value), do |
|
430 |
* <em>not</em> influence the results of this method. In other |
|
431 |
* words, the numerical value of the input string is converted |
|
432 |
* directly to the target floating-point type. The two-step |
|
433 |
* sequence of conversions, string to {@code float} followed |
|
434 |
* by {@code float} to {@code double}, is <em>not</em> |
|
435 |
* equivalent to converting a string directly to |
|
436 |
* {@code double}. For example, the {@code float} |
|
437 |
* literal {@code 0.1f} is equal to the {@code double} |
|
438 |
* value {@code 0.10000000149011612}; the {@code float} |
|
439 |
* literal {@code 0.1f} represents a different numerical |
|
440 |
* value than the {@code double} literal |
|
441 |
* {@code 0.1}. (The numerical value 0.1 cannot be exactly |
|
442 |
* represented in a binary floating-point number.) |
|
443 |
* |
|
444 |
* <p>To avoid calling this method on an invalid string and having |
|
445 |
* a {@code NumberFormatException} be thrown, the regular |
|
446 |
* expression below can be used to screen the input string: |
|
447 |
* |
|
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
18156
diff
changeset
|
448 |
* <pre>{@code |
2 | 449 |
* final String Digits = "(\\p{Digit}+)"; |
450 |
* final String HexDigits = "(\\p{XDigit}+)"; |
|
451 |
* // an exponent is 'e' or 'E' followed by an optionally |
|
452 |
* // signed decimal integer. |
|
453 |
* final String Exp = "[eE][+-]?"+Digits; |
|
454 |
* final String fpRegex = |
|
455 |
* ("[\\x00-\\x20]*"+ // Optional leading "whitespace" |
|
456 |
* "[+-]?(" + // Optional sign character |
|
457 |
* "NaN|" + // "NaN" string |
|
458 |
* "Infinity|" + // "Infinity" string |
|
459 |
* |
|
460 |
* // A decimal floating-point string representing a finite positive |
|
461 |
* // number without a leading sign has at most five basic pieces: |
|
462 |
* // Digits . Digits ExponentPart FloatTypeSuffix |
|
463 |
* // |
|
464 |
* // Since this method allows integer-only strings as input |
|
465 |
* // in addition to strings of floating-point literals, the |
|
466 |
* // two sub-patterns below are simplifications of the grammar |
|
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7517
diff
changeset
|
467 |
* // productions from section 3.10.2 of |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
18156
diff
changeset
|
468 |
* // The Java Language Specification. |
2 | 469 |
* |
470 |
* // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt |
|
471 |
* "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+ |
|
472 |
* |
|
473 |
* // . Digits ExponentPart_opt FloatTypeSuffix_opt |
|
474 |
* "(\\.("+Digits+")("+Exp+")?)|"+ |
|
475 |
* |
|
476 |
* // Hexadecimal strings |
|
477 |
* "((" + |
|
478 |
* // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt |
|
479 |
* "(0[xX]" + HexDigits + "(\\.)?)|" + |
|
480 |
* |
|
481 |
* // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt |
|
482 |
* "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + |
|
483 |
* |
|
484 |
* ")[pP][+-]?" + Digits + "))" + |
|
485 |
* "[fFdD]?))" + |
|
486 |
* "[\\x00-\\x20]*");// Optional trailing "whitespace" |
|
487 |
* |
|
488 |
* if (Pattern.matches(fpRegex, myString)) |
|
489 |
* Double.valueOf(myString); // Will not throw NumberFormatException |
|
490 |
* else { |
|
491 |
* // Perform suitable alternative action |
|
492 |
* } |
|
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
18156
diff
changeset
|
493 |
* }</pre> |
2 | 494 |
* |
495 |
* @param s the string to be parsed. |
|
496 |
* @return a {@code Double} object holding the value |
|
497 |
* represented by the {@code String} argument. |
|
498 |
* @throws NumberFormatException if the string does not contain a |
|
499 |
* parsable number. |
|
500 |
*/ |
|
501 |
public static Double valueOf(String s) throws NumberFormatException { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
15525
diff
changeset
|
502 |
return new Double(parseDouble(s)); |
2 | 503 |
} |
504 |
||
505 |
/** |
|
506 |
* Returns a {@code Double} instance representing the specified |
|
507 |
* {@code double} value. |
|
508 |
* If a new {@code Double} instance is not required, this method |
|
509 |
* should generally be used in preference to the constructor |
|
510 |
* {@link #Double(double)}, as this method is likely to yield |
|
511 |
* significantly better space and time performance by caching |
|
512 |
* frequently requested values. |
|
513 |
* |
|
514 |
* @param d a double value. |
|
515 |
* @return a {@code Double} instance representing {@code d}. |
|
516 |
* @since 1.5 |
|
517 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
518 |
@HotSpotIntrinsicCandidate |
2 | 519 |
public static Double valueOf(double d) { |
520 |
return new Double(d); |
|
521 |
} |
|
522 |
||
523 |
/** |
|
524 |
* Returns a new {@code double} initialized to the value |
|
525 |
* represented by the specified {@code String}, as performed |
|
526 |
* by the {@code valueOf} method of class |
|
527 |
* {@code Double}. |
|
528 |
* |
|
529 |
* @param s the string to be parsed. |
|
530 |
* @return the {@code double} value represented by the string |
|
531 |
* argument. |
|
3312
d8cd9665ece8
6463998: Undocumented NullPointerExeption from Float.parseFloat and Double.parseDouble
darcy
parents:
1824
diff
changeset
|
532 |
* @throws NullPointerException if the string is null |
2 | 533 |
* @throws NumberFormatException if the string does not contain |
534 |
* a parsable {@code double}. |
|
535 |
* @see java.lang.Double#valueOf(String) |
|
536 |
* @since 1.2 |
|
537 |
*/ |
|
538 |
public static double parseDouble(String s) throws NumberFormatException { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
15525
diff
changeset
|
539 |
return FloatingDecimal.parseDouble(s); |
2 | 540 |
} |
541 |
||
542 |
/** |
|
543 |
* Returns {@code true} if the specified number is a |
|
544 |
* Not-a-Number (NaN) value, {@code false} otherwise. |
|
545 |
* |
|
546 |
* @param v the value to be tested. |
|
547 |
* @return {@code true} if the value of the argument is NaN; |
|
548 |
* {@code false} otherwise. |
|
549 |
*/ |
|
10608 | 550 |
public static boolean isNaN(double v) { |
2 | 551 |
return (v != v); |
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* Returns {@code true} if the specified number is infinitely |
|
556 |
* large in magnitude, {@code false} otherwise. |
|
557 |
* |
|
558 |
* @param v the value to be tested. |
|
559 |
* @return {@code true} if the value of the argument is positive |
|
560 |
* infinity or negative infinity; {@code false} otherwise. |
|
561 |
*/ |
|
10608 | 562 |
public static boolean isInfinite(double v) { |
2 | 563 |
return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY); |
564 |
} |
|
565 |
||
566 |
/** |
|
10608 | 567 |
* Returns {@code true} if the argument is a finite floating-point |
568 |
* value; returns {@code false} otherwise (for NaN and infinity |
|
569 |
* arguments). |
|
570 |
* |
|
571 |
* @param d the {@code double} value to be tested |
|
572 |
* @return {@code true} if the argument is a finite |
|
573 |
* floating-point value, {@code false} otherwise. |
|
574 |
* @since 1.8 |
|
575 |
*/ |
|
576 |
public static boolean isFinite(double d) { |
|
35979
4462913d471a
8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents:
34781
diff
changeset
|
577 |
return Math.abs(d) <= Double.MAX_VALUE; |
10608 | 578 |
} |
579 |
||
580 |
/** |
|
2 | 581 |
* The value of the Double. |
582 |
* |
|
583 |
* @serial |
|
584 |
*/ |
|
585 |
private final double value; |
|
586 |
||
587 |
/** |
|
588 |
* Constructs a newly allocated {@code Double} object that |
|
589 |
* represents the primitive {@code double} argument. |
|
590 |
* |
|
591 |
* @param value the value to be represented by the {@code Double}. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
592 |
* |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
593 |
* @deprecated |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
594 |
* It is rarely appropriate to use this constructor. The static factory |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
595 |
* {@link #valueOf(double)} is generally a better choice, as it is |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
596 |
* likely to yield significantly better space and time performance. |
2 | 597 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
598 |
@Deprecated(since="9") |
2 | 599 |
public Double(double value) { |
600 |
this.value = value; |
|
601 |
} |
|
602 |
||
603 |
/** |
|
604 |
* Constructs a newly allocated {@code Double} object that |
|
605 |
* represents the floating-point value of type {@code double} |
|
606 |
* represented by the string. The string is converted to a |
|
607 |
* {@code double} value as if by the {@code valueOf} method. |
|
608 |
* |
|
609 |
* @param s a string to be converted to a {@code Double}. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
610 |
* @throws NumberFormatException if the string does not contain a |
2 | 611 |
* parsable number. |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
612 |
* |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
613 |
* @deprecated |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
614 |
* It is rarely appropriate to use this constructor. |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
615 |
* Use {@link #parseDouble(String)} to convert a string to a |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
616 |
* {@code double} primitive, or use {@link #valueOf(String)} |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
617 |
* to convert a string to a {@code Double} object. |
2 | 618 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
35979
diff
changeset
|
619 |
@Deprecated(since="9") |
2 | 620 |
public Double(String s) throws NumberFormatException { |
11016
e2665f4ac6d2
7110111: Minor Java SE javadoc & Constructor clean up
lancea
parents:
10608
diff
changeset
|
621 |
value = parseDouble(s); |
2 | 622 |
} |
623 |
||
624 |
/** |
|
625 |
* Returns {@code true} if this {@code Double} value is |
|
626 |
* a Not-a-Number (NaN), {@code false} otherwise. |
|
627 |
* |
|
628 |
* @return {@code true} if the value represented by this object is |
|
629 |
* NaN; {@code false} otherwise. |
|
630 |
*/ |
|
631 |
public boolean isNaN() { |
|
632 |
return isNaN(value); |
|
633 |
} |
|
634 |
||
635 |
/** |
|
636 |
* Returns {@code true} if this {@code Double} value is |
|
637 |
* infinitely large in magnitude, {@code false} otherwise. |
|
638 |
* |
|
639 |
* @return {@code true} if the value represented by this object is |
|
640 |
* positive infinity or negative infinity; |
|
641 |
* {@code false} otherwise. |
|
642 |
*/ |
|
643 |
public boolean isInfinite() { |
|
644 |
return isInfinite(value); |
|
645 |
} |
|
646 |
||
647 |
/** |
|
648 |
* Returns a string representation of this {@code Double} object. |
|
649 |
* The primitive {@code double} value represented by this |
|
650 |
* object is converted to a string exactly as if by the method |
|
651 |
* {@code toString} of one argument. |
|
652 |
* |
|
653 |
* @return a {@code String} representation of this object. |
|
654 |
* @see java.lang.Double#toString(double) |
|
655 |
*/ |
|
656 |
public String toString() { |
|
3964
cf913644be58
6480728: Byte.valueOf(byte) returns a cached value but Byte.valueOf(String)
darcy
parents:
3312
diff
changeset
|
657 |
return toString(value); |
2 | 658 |
} |
659 |
||
660 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
661 |
* Returns the value of this {@code Double} as a {@code byte} |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
662 |
* after a narrowing primitive conversion. |
2 | 663 |
* |
664 |
* @return the {@code double} value represented by this object |
|
665 |
* converted to type {@code byte} |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
666 |
* @jls 5.1.3 Narrowing Primitive Conversions |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22634
diff
changeset
|
667 |
* @since 1.1 |
2 | 668 |
*/ |
669 |
public byte byteValue() { |
|
670 |
return (byte)value; |
|
671 |
} |
|
672 |
||
673 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
674 |
* Returns the value of this {@code Double} as a {@code short} |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
675 |
* after a narrowing primitive conversion. |
2 | 676 |
* |
677 |
* @return the {@code double} value represented by this object |
|
678 |
* converted to type {@code short} |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
679 |
* @jls 5.1.3 Narrowing Primitive Conversions |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22634
diff
changeset
|
680 |
* @since 1.1 |
2 | 681 |
*/ |
682 |
public short shortValue() { |
|
683 |
return (short)value; |
|
684 |
} |
|
685 |
||
686 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
687 |
* Returns the value of this {@code Double} as an {@code int} |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
688 |
* after a narrowing primitive conversion. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
689 |
* @jls 5.1.3 Narrowing Primitive Conversions |
2 | 690 |
* |
691 |
* @return the {@code double} value represented by this object |
|
692 |
* converted to type {@code int} |
|
693 |
*/ |
|
694 |
public int intValue() { |
|
695 |
return (int)value; |
|
696 |
} |
|
697 |
||
698 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
699 |
* Returns the value of this {@code Double} as a {@code long} |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
700 |
* after a narrowing primitive conversion. |
2 | 701 |
* |
702 |
* @return the {@code double} value represented by this object |
|
703 |
* converted to type {@code long} |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
704 |
* @jls 5.1.3 Narrowing Primitive Conversions |
2 | 705 |
*/ |
706 |
public long longValue() { |
|
707 |
return (long)value; |
|
708 |
} |
|
709 |
||
710 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
711 |
* Returns the value of this {@code Double} as a {@code float} |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
712 |
* after a narrowing primitive conversion. |
2 | 713 |
* |
714 |
* @return the {@code double} value represented by this object |
|
715 |
* converted to type {@code float} |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
716 |
* @jls 5.1.3 Narrowing Primitive Conversions |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22634
diff
changeset
|
717 |
* @since 1.0 |
2 | 718 |
*/ |
719 |
public float floatValue() { |
|
720 |
return (float)value; |
|
721 |
} |
|
722 |
||
723 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
9266
diff
changeset
|
724 |
* Returns the {@code double} value of this {@code Double} object. |
2 | 725 |
* |
726 |
* @return the {@code double} value represented by this object |
|
727 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
728 |
@HotSpotIntrinsicCandidate |
2 | 729 |
public double doubleValue() { |
11275 | 730 |
return value; |
2 | 731 |
} |
732 |
||
733 |
/** |
|
734 |
* Returns a hash code for this {@code Double} object. The |
|
735 |
* result is the exclusive OR of the two halves of the |
|
736 |
* {@code long} integer bit representation, exactly as |
|
737 |
* produced by the method {@link #doubleToLongBits(double)}, of |
|
738 |
* the primitive {@code double} value represented by this |
|
739 |
* {@code Double} object. That is, the hash code is the value |
|
740 |
* of the expression: |
|
741 |
* |
|
742 |
* <blockquote> |
|
743 |
* {@code (int)(v^(v>>>32))} |
|
744 |
* </blockquote> |
|
745 |
* |
|
746 |
* where {@code v} is defined by: |
|
747 |
* |
|
748 |
* <blockquote> |
|
749 |
* {@code long v = Double.doubleToLongBits(this.doubleValue());} |
|
750 |
* </blockquote> |
|
751 |
* |
|
752 |
* @return a {@code hash code} value for this object. |
|
753 |
*/ |
|
14503
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
754 |
@Override |
2 | 755 |
public int hashCode() { |
14503
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
756 |
return Double.hashCode(value); |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
757 |
} |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
758 |
|
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
759 |
/** |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
760 |
* Returns a hash code for a {@code double} value; compatible with |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
761 |
* {@code Double.hashCode()}. |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
762 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
18156
diff
changeset
|
763 |
* @param value the value to hash |
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
18156
diff
changeset
|
764 |
* @return a hash code value for a {@code double} value. |
14503
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
765 |
* @since 1.8 |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
766 |
*/ |
0729d9e57ed5
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents:
11676
diff
changeset
|
767 |
public static int hashCode(double value) { |
2 | 768 |
long bits = doubleToLongBits(value); |
769 |
return (int)(bits ^ (bits >>> 32)); |
|
770 |
} |
|
771 |
||
772 |
/** |
|
773 |
* Compares this object against the specified object. The result |
|
774 |
* is {@code true} if and only if the argument is not |
|
775 |
* {@code null} and is a {@code Double} object that |
|
776 |
* represents a {@code double} that has the same value as the |
|
777 |
* {@code double} represented by this object. For this |
|
778 |
* purpose, two {@code double} values are considered to be |
|
779 |
* the same if and only if the method {@link |
|
780 |
* #doubleToLongBits(double)} returns the identical |
|
781 |
* {@code long} value when applied to each. |
|
782 |
* |
|
783 |
* <p>Note that in most cases, for two instances of class |
|
784 |
* {@code Double}, {@code d1} and {@code d2}, the |
|
785 |
* value of {@code d1.equals(d2)} is {@code true} if and |
|
786 |
* only if |
|
787 |
* |
|
788 |
* <blockquote> |
|
789 |
* {@code d1.doubleValue() == d2.doubleValue()} |
|
790 |
* </blockquote> |
|
791 |
* |
|
792 |
* <p>also has the value {@code true}. However, there are two |
|
793 |
* exceptions: |
|
794 |
* <ul> |
|
795 |
* <li>If {@code d1} and {@code d2} both represent |
|
796 |
* {@code Double.NaN}, then the {@code equals} method |
|
797 |
* returns {@code true}, even though |
|
798 |
* {@code Double.NaN==Double.NaN} has the value |
|
799 |
* {@code false}. |
|
800 |
* <li>If {@code d1} represents {@code +0.0} while |
|
801 |
* {@code d2} represents {@code -0.0}, or vice versa, |
|
802 |
* the {@code equal} test has the value {@code false}, |
|
803 |
* even though {@code +0.0==-0.0} has the value {@code true}. |
|
804 |
* </ul> |
|
805 |
* This definition allows hash tables to operate properly. |
|
806 |
* @param obj the object to compare with. |
|
807 |
* @return {@code true} if the objects are the same; |
|
808 |
* {@code false} otherwise. |
|
809 |
* @see java.lang.Double#doubleToLongBits(double) |
|
810 |
*/ |
|
811 |
public boolean equals(Object obj) { |
|
812 |
return (obj instanceof Double) |
|
813 |
&& (doubleToLongBits(((Double)obj).value) == |
|
814 |
doubleToLongBits(value)); |
|
815 |
} |
|
816 |
||
817 |
/** |
|
818 |
* Returns a representation of the specified floating-point value |
|
819 |
* according to the IEEE 754 floating-point "double |
|
820 |
* format" bit layout. |
|
821 |
* |
|
822 |
* <p>Bit 63 (the bit that is selected by the mask |
|
823 |
* {@code 0x8000000000000000L}) represents the sign of the |
|
824 |
* floating-point number. Bits |
|
825 |
* 62-52 (the bits that are selected by the mask |
|
826 |
* {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0 |
|
827 |
* (the bits that are selected by the mask |
|
828 |
* {@code 0x000fffffffffffffL}) represent the significand |
|
829 |
* (sometimes called the mantissa) of the floating-point number. |
|
830 |
* |
|
831 |
* <p>If the argument is positive infinity, the result is |
|
832 |
* {@code 0x7ff0000000000000L}. |
|
833 |
* |
|
834 |
* <p>If the argument is negative infinity, the result is |
|
835 |
* {@code 0xfff0000000000000L}. |
|
836 |
* |
|
837 |
* <p>If the argument is NaN, the result is |
|
838 |
* {@code 0x7ff8000000000000L}. |
|
839 |
* |
|
840 |
* <p>In all cases, the result is a {@code long} integer that, when |
|
841 |
* given to the {@link #longBitsToDouble(long)} method, will produce a |
|
842 |
* floating-point value the same as the argument to |
|
843 |
* {@code doubleToLongBits} (except all NaN values are |
|
844 |
* collapsed to a single "canonical" NaN value). |
|
845 |
* |
|
846 |
* @param value a {@code double} precision floating-point number. |
|
847 |
* @return the bits that represent the floating-point number. |
|
848 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
849 |
@HotSpotIntrinsicCandidate |
2 | 850 |
public static long doubleToLongBits(double value) { |
22290
6d4551cf4b3e
6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents:
21334
diff
changeset
|
851 |
if (!isNaN(value)) { |
6d4551cf4b3e
6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents:
21334
diff
changeset
|
852 |
return doubleToRawLongBits(value); |
6d4551cf4b3e
6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents:
21334
diff
changeset
|
853 |
} |
6d4551cf4b3e
6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents:
21334
diff
changeset
|
854 |
return 0x7ff8000000000000L; |
2 | 855 |
} |
856 |
||
857 |
/** |
|
858 |
* Returns a representation of the specified floating-point value |
|
859 |
* according to the IEEE 754 floating-point "double |
|
860 |
* format" bit layout, preserving Not-a-Number (NaN) values. |
|
861 |
* |
|
862 |
* <p>Bit 63 (the bit that is selected by the mask |
|
863 |
* {@code 0x8000000000000000L}) represents the sign of the |
|
864 |
* floating-point number. Bits |
|
865 |
* 62-52 (the bits that are selected by the mask |
|
866 |
* {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0 |
|
867 |
* (the bits that are selected by the mask |
|
868 |
* {@code 0x000fffffffffffffL}) represent the significand |
|
869 |
* (sometimes called the mantissa) of the floating-point number. |
|
870 |
* |
|
871 |
* <p>If the argument is positive infinity, the result is |
|
872 |
* {@code 0x7ff0000000000000L}. |
|
873 |
* |
|
874 |
* <p>If the argument is negative infinity, the result is |
|
875 |
* {@code 0xfff0000000000000L}. |
|
876 |
* |
|
877 |
* <p>If the argument is NaN, the result is the {@code long} |
|
878 |
* integer representing the actual NaN value. Unlike the |
|
879 |
* {@code doubleToLongBits} method, |
|
880 |
* {@code doubleToRawLongBits} does not collapse all the bit |
|
881 |
* patterns encoding a NaN to a single "canonical" NaN |
|
882 |
* value. |
|
883 |
* |
|
884 |
* <p>In all cases, the result is a {@code long} integer that, |
|
885 |
* when given to the {@link #longBitsToDouble(long)} method, will |
|
886 |
* produce a floating-point value the same as the argument to |
|
887 |
* {@code doubleToRawLongBits}. |
|
888 |
* |
|
889 |
* @param value a {@code double} precision floating-point number. |
|
890 |
* @return the bits that represent the floating-point number. |
|
891 |
* @since 1.3 |
|
892 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
893 |
@HotSpotIntrinsicCandidate |
2 | 894 |
public static native long doubleToRawLongBits(double value); |
895 |
||
896 |
/** |
|
897 |
* Returns the {@code double} value corresponding to a given |
|
898 |
* bit representation. |
|
899 |
* The argument is considered to be a representation of a |
|
900 |
* floating-point value according to the IEEE 754 floating-point |
|
901 |
* "double format" bit layout. |
|
902 |
* |
|
903 |
* <p>If the argument is {@code 0x7ff0000000000000L}, the result |
|
904 |
* is positive infinity. |
|
905 |
* |
|
906 |
* <p>If the argument is {@code 0xfff0000000000000L}, the result |
|
907 |
* is negative infinity. |
|
908 |
* |
|
909 |
* <p>If the argument is any value in the range |
|
910 |
* {@code 0x7ff0000000000001L} through |
|
911 |
* {@code 0x7fffffffffffffffL} or in the range |
|
912 |
* {@code 0xfff0000000000001L} through |
|
913 |
* {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE |
|
914 |
* 754 floating-point operation provided by Java can distinguish |
|
915 |
* between two NaN values of the same type with different bit |
|
916 |
* patterns. Distinct values of NaN are only distinguishable by |
|
917 |
* use of the {@code Double.doubleToRawLongBits} method. |
|
918 |
* |
|
919 |
* <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three |
|
920 |
* values that can be computed from the argument: |
|
921 |
* |
|
18156 | 922 |
* <blockquote><pre>{@code |
923 |
* int s = ((bits >> 63) == 0) ? 1 : -1; |
|
924 |
* int e = (int)((bits >> 52) & 0x7ffL); |
|
2 | 925 |
* long m = (e == 0) ? |
18156 | 926 |
* (bits & 0xfffffffffffffL) << 1 : |
2 | 927 |
* (bits & 0xfffffffffffffL) | 0x10000000000000L; |
18156 | 928 |
* }</pre></blockquote> |
2 | 929 |
* |
930 |
* Then the floating-point result equals the value of the mathematical |
|
931 |
* expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-1075</sup>. |
|
932 |
* |
|
933 |
* <p>Note that this method may not be able to return a |
|
934 |
* {@code double} NaN with exactly same bit pattern as the |
|
935 |
* {@code long} argument. IEEE 754 distinguishes between two |
|
936 |
* kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The |
|
937 |
* differences between the two kinds of NaN are generally not |
|
938 |
* visible in Java. Arithmetic operations on signaling NaNs turn |
|
939 |
* them into quiet NaNs with a different, but often similar, bit |
|
940 |
* pattern. However, on some processors merely copying a |
|
941 |
* signaling NaN also performs that conversion. In particular, |
|
942 |
* copying a signaling NaN to return it to the calling method |
|
943 |
* may perform this conversion. So {@code longBitsToDouble} |
|
944 |
* may not be able to return a {@code double} with a |
|
945 |
* signaling NaN bit pattern. Consequently, for some |
|
946 |
* {@code long} values, |
|
947 |
* {@code doubleToRawLongBits(longBitsToDouble(start))} may |
|
948 |
* <i>not</i> equal {@code start}. Moreover, which |
|
949 |
* particular bit patterns represent signaling NaNs is platform |
|
950 |
* dependent; although all NaN bit patterns, quiet or signaling, |
|
951 |
* must be in the NaN range identified above. |
|
952 |
* |
|
953 |
* @param bits any {@code long} integer. |
|
954 |
* @return the {@code double} floating-point value with the same |
|
955 |
* bit pattern. |
|
956 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
957 |
@HotSpotIntrinsicCandidate |
2 | 958 |
public static native double longBitsToDouble(long bits); |
959 |
||
960 |
/** |
|
961 |
* Compares two {@code Double} objects numerically. There |
|
962 |
* are two ways in which comparisons performed by this method |
|
963 |
* differ from those performed by the Java language numerical |
|
964 |
* comparison operators ({@code <, <=, ==, >=, >}) |
|
965 |
* when applied to primitive {@code double} values: |
|
966 |
* <ul><li> |
|
967 |
* {@code Double.NaN} is considered by this method |
|
968 |
* to be equal to itself and greater than all other |
|
969 |
* {@code double} values (including |
|
970 |
* {@code Double.POSITIVE_INFINITY}). |
|
971 |
* <li> |
|
972 |
* {@code 0.0d} is considered by this method to be greater |
|
973 |
* than {@code -0.0d}. |
|
974 |
* </ul> |
|
975 |
* This ensures that the <i>natural ordering</i> of |
|
976 |
* {@code Double} objects imposed by this method is <i>consistent |
|
977 |
* with equals</i>. |
|
978 |
* |
|
979 |
* @param anotherDouble the {@code Double} to be compared. |
|
980 |
* @return the value {@code 0} if {@code anotherDouble} is |
|
981 |
* numerically equal to this {@code Double}; a value |
|
982 |
* less than {@code 0} if this {@code Double} |
|
983 |
* is numerically less than {@code anotherDouble}; |
|
984 |
* and a value greater than {@code 0} if this |
|
985 |
* {@code Double} is numerically greater than |
|
986 |
* {@code anotherDouble}. |
|
987 |
* |
|
988 |
* @since 1.2 |
|
989 |
*/ |
|
990 |
public int compareTo(Double anotherDouble) { |
|
991 |
return Double.compare(value, anotherDouble.value); |
|
992 |
} |
|
993 |
||
994 |
/** |
|
995 |
* Compares the two specified {@code double} values. The sign |
|
996 |
* of the integer value returned is the same as that of the |
|
997 |
* integer that would be returned by the call: |
|
998 |
* <pre> |
|
999 |
* new Double(d1).compareTo(new Double(d2)) |
|
1000 |
* </pre> |
|
1001 |
* |
|
1002 |
* @param d1 the first {@code double} to compare |
|
1003 |
* @param d2 the second {@code double} to compare |
|
1004 |
* @return the value {@code 0} if {@code d1} is |
|
1005 |
* numerically equal to {@code d2}; a value less than |
|
1006 |
* {@code 0} if {@code d1} is numerically less than |
|
1007 |
* {@code d2}; and a value greater than {@code 0} |
|
1008 |
* if {@code d1} is numerically greater than |
|
1009 |
* {@code d2}. |
|
1010 |
* @since 1.4 |
|
1011 |
*/ |
|
1012 |
public static int compare(double d1, double d2) { |
|
1013 |
if (d1 < d2) |
|
1014 |
return -1; // Neither val is NaN, thisVal is smaller |
|
1015 |
if (d1 > d2) |
|
1016 |
return 1; // Neither val is NaN, thisVal is larger |
|
1017 |
||
7517
7303bc0e78d6
7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents:
5506
diff
changeset
|
1018 |
// Cannot use doubleToRawLongBits because of possibility of NaNs. |
7303bc0e78d6
7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents:
5506
diff
changeset
|
1019 |
long thisBits = Double.doubleToLongBits(d1); |
2 | 1020 |
long anotherBits = Double.doubleToLongBits(d2); |
1021 |
||
1022 |
return (thisBits == anotherBits ? 0 : // Values are equal |
|
1023 |
(thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN) |
|
1024 |
1)); // (0.0, -0.0) or (NaN, !NaN) |
|
1025 |
} |
|
1026 |
||
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1027 |
/** |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1028 |
* Adds two {@code double} values together as per the + operator. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1029 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1030 |
* @param a the first operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1031 |
* @param b the second operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1032 |
* @return the sum of {@code a} and {@code b} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1033 |
* @jls 4.2.4 Floating-Point Operations |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1034 |
* @see java.util.function.BinaryOperator |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1035 |
* @since 1.8 |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1036 |
*/ |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1037 |
public static double sum(double a, double b) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1038 |
return a + b; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1039 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1040 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1041 |
/** |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1042 |
* Returns the greater of two {@code double} values |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1043 |
* as if by calling {@link Math#max(double, double) Math.max}. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1044 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1045 |
* @param a the first operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1046 |
* @param b the second operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1047 |
* @return the greater of {@code a} and {@code b} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1048 |
* @see java.util.function.BinaryOperator |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1049 |
* @since 1.8 |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1050 |
*/ |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1051 |
public static double max(double a, double b) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1052 |
return Math.max(a, b); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1053 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1054 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1055 |
/** |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1056 |
* Returns the smaller of two {@code double} values |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1057 |
* as if by calling {@link Math#min(double, double) Math.min}. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1058 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1059 |
* @param a the first operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1060 |
* @param b the second operand |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1061 |
* @return the smaller of {@code a} and {@code b}. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1062 |
* @see java.util.function.BinaryOperator |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1063 |
* @since 1.8 |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1064 |
*/ |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1065 |
public static double min(double a, double b) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1066 |
return Math.min(a, b); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1067 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
14507
diff
changeset
|
1068 |
|
2 | 1069 |
/** use serialVersionUID from JDK 1.0.2 for interoperability */ |
1070 |
private static final long serialVersionUID = -9172774392245257468L; |
|
1071 |
} |