1 /* 2 * Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 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.vm.annotation.IntrinsicCandidate; 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 * <!-- Android-removed: paragraph on ValueBased 50 * <p>This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a> 51 * class; programmers should treat instances that are 52 * {@linkplain #equals(Object) equal} as interchangeable and should not 53 * use instances for synchronization, or unpredictable behavior may 54 * occur. For example, in a future release, synchronization may fail. 55 * --> 56 * 57 * <h2><a id=equivalenceRelation>Floating-point Equality, Equivalence, 58 * and Comparison</a></h2> 59 * 60 * IEEE 754 floating-point values include finite nonzero values, 61 * signed zeros ({@code +0.0} and {@code -0.0}), signed infinities 62 * {@linkplain Double#POSITIVE_INFINITY positive infinity} and 63 * {@linkplain Double#NEGATIVE_INFINITY negative infinity}), and 64 * {@linkplain Double#NaN NaN} (not-a-number). 65 * 66 * <p>An <em>equivalence relation</em> on a set of values is a boolean 67 * relation on pairs of values that is reflexive, symmetric, and 68 * transitive. For more discussion of equivalence relations and object 69 * equality, see the {@link Object#equals Object.equals} 70 * specification. An equivalence relation partitions the values it 71 * operates over into sets called <i>equivalence classes</i>. All the 72 * members of the equivalence class are equal to each other under the 73 * relation. An equivalence class may contain only a single member. At 74 * least for some purposes, all the members of an equivalence class 75 * are substitutable for each other. In particular, in a numeric 76 * expression equivalent values can be <em>substituted</em> for one 77 * another without changing the result of the expression, meaning 78 * changing the equivalence class of the result of the expression. 79 * 80 * <p>Notably, the built-in {@code ==} operation on floating-point 81 * values is <em>not</em> an equivalence relation. Despite not 82 * defining an equivalence relation, the semantics of the IEEE 754 83 * {@code ==} operator were deliberately designed to meet other needs 84 * of numerical computation. There are two exceptions where the 85 * properties of an equivalence relation are not satisfied by {@code 86 * ==} on floating-point values: 87 * 88 * <ul> 89 * 90 * <li>If {@code v1} and {@code v2} are both NaN, then {@code v1 91 * == v2} has the value {@code false}. Therefore, for two NaN 92 * arguments the <em>reflexive</em> property of an equivalence 93 * relation is <em>not</em> satisfied by the {@code ==} operator. 94 * 95 * <li>If {@code v1} represents {@code +0.0} while {@code v2} 96 * represents {@code -0.0}, or vice versa, then {@code v1 == v2} has 97 * the value {@code true} even though {@code +0.0} and {@code -0.0} 98 * are distinguishable under various floating-point operations. For 99 * example, {@code 1.0/+0.0} evaluates to positive infinity while 100 * {@code 1.0/-0.0} evaluates to <em>negative</em> infinity and 101 * positive infinity and negative infinity are neither equal to each 102 * other nor equivalent to each other. Thus, while a signed zero input 103 * most commonly determines the sign of a zero result, because of 104 * dividing by zero, {@code +0.0} and {@code -0.0} may not be 105 * substituted for each other in general. The sign of a zero input 106 * also has a non-substitutable effect on the result of some math 107 * library methods. 108 * 109 * </ul> 110 * 111 * <p>For ordered comparisons using the built-in comparison operators 112 * ({@code <}, {@code <=}, etc.), NaN values have another anomalous 113 * situation: a NaN is neither less than, nor greater than, nor equal 114 * to any value, including itself. This means the <i>trichotomy of 115 * comparison</i> does <em>not</em> hold. 116 * 117 * <p>To provide the appropriate semantics for {@code equals} and 118 * {@code compareTo} methods, those methods cannot simply be wrappers 119 * around {@code ==} or ordered comparison operations. Instead, {@link 120 * Double#equals equals} defines NaN arguments to be equal to each 121 * other and defines {@code +0.0} to <em>not</em> be equal to {@code 122 * -0.0}, restoring reflexivity. For comparisons, {@link 123 * Double#compareTo compareTo} defines a total order where {@code 124 * -0.0} is less than {@code +0.0} and where a NaN is equal to itself 125 * and considered greater than positive infinity. 126 * 127 * <p>The operational semantics of {@code equals} and {@code 128 * compareTo} are expressed in terms of {@linkplain #doubleToLongBits 129 * bit-wise converting} the floating-point values to integral values. 130 * 131 * <p>The <em>natural ordering</em> implemented by {@link #compareTo 132 * compareTo} is {@linkplain Comparable consistent with equals}. That 133 * is, two objects are reported as equal by {@code equals} if and only 134 * if {@code compareTo} on those objects returns zero. 135 * 136 * <p>The adjusted behaviors defined for {@code equals} and {@code 137 * compareTo} allow instances of wrapper classes to work properly with 138 * conventional data structures. For example, defining NaN 139 * values to be {@code equals} to one another allows NaN to be used as 140 * an element of a {@link java.util.HashSet HashSet} or as the key of 141 * a {@link java.util.HashMap HashMap}. Similarly, defining {@code 142 * compareTo} as a total ordering, including {@code +0.0}, {@code 143 * -0.0}, and NaN, allows instances of wrapper classes to be used as 144 * elements of a {@link java.util.SortedSet SortedSet} or as keys of a 145 * {@link java.util.SortedMap SortedMap}. 146 * 147 * @jls 4.2.3 Floating-Point Types, Formats, and Values 148 * @jls 4.2.4. Floating-Point Operations 149 * @jls 15.21.1 Numerical Equality Operators == and != 150 * @jls 15.20.1 Numerical Comparison Operators {@code <}, {@code <=}, {@code >}, and {@code >=} 151 * 152 * @author Lee Boynton 153 * @author Arthur van Hoff 154 * @author Joseph D. Darcy 155 * @since 1.0 156 */ 157 @jdk.internal.ValueBased 158 public final class Double extends Number 159 implements Comparable<Double>, Constable, ConstantDesc { 160 /** 161 * A constant holding the positive infinity of type 162 * {@code double}. It is equal to the value returned by 163 * {@code Double.longBitsToDouble(0x7ff0000000000000L)}. 164 */ 165 public static final double POSITIVE_INFINITY = 1.0 / 0.0; 166 167 /** 168 * A constant holding the negative infinity of type 169 * {@code double}. It is equal to the value returned by 170 * {@code Double.longBitsToDouble(0xfff0000000000000L)}. 171 */ 172 public static final double NEGATIVE_INFINITY = -1.0 / 0.0; 173 174 /** 175 * A constant holding a Not-a-Number (NaN) value of type 176 * {@code double}. It is equivalent to the value returned by 177 * {@code Double.longBitsToDouble(0x7ff8000000000000L)}. 178 */ 179 public static final double NaN = 0.0d / 0.0; 180 181 /** 182 * A constant holding the largest positive finite value of type 183 * {@code double}, 184 * (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to 185 * the hexadecimal floating-point literal 186 * {@code 0x1.fffffffffffffP+1023} and also equal to 187 * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}. 188 */ 189 public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308 190 191 /** 192 * A constant holding the smallest positive normal value of type 193 * {@code double}, 2<sup>-1022</sup>. It is equal to the 194 * hexadecimal floating-point literal {@code 0x1.0p-1022} and also 195 * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}. 196 * 197 * @since 1.6 198 */ 199 public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308 200 201 /** 202 * A constant holding the smallest positive nonzero value of type 203 * {@code double}, 2<sup>-1074</sup>. It is equal to the 204 * hexadecimal floating-point literal 205 * {@code 0x0.0000000000001P-1022} and also equal to 206 * {@code Double.longBitsToDouble(0x1L)}. 207 */ 208 public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324 209 210 /** 211 * Maximum exponent a finite {@code double} variable may have. 212 * It is equal to the value returned by 213 * {@code Math.getExponent(Double.MAX_VALUE)}. 214 * 215 * @since 1.6 216 */ 217 public static final int MAX_EXPONENT = 1023; 218 219 /** 220 * Minimum exponent a normalized {@code double} variable may 221 * have. It is equal to the value returned by 222 * {@code Math.getExponent(Double.MIN_NORMAL)}. 223 * 224 * @since 1.6 225 */ 226 public static final int MIN_EXPONENT = -1022; 227 228 /** 229 * The number of bits used to represent a {@code double} value. 230 * 231 * @since 1.5 232 */ 233 public static final int SIZE = 64; 234 235 /** 236 * The number of bits in the significand of a {@code double} value. 237 * This is the parameter N in section {@jls 4.2.3} of 238 * <cite>The Java Language Specification</cite>. 239 * 240 * @since 19 241 */ 242 public static final int PRECISION = 53; 243 244 /** 245 * The number of bytes used to represent a {@code double} value. 246 * 247 * @since 1.8 248 */ 249 public static final int BYTES = SIZE / Byte.SIZE; 250 251 /** 252 * The {@code Class} instance representing the primitive type 253 * {@code double}. 254 * 255 * @since 1.1 256 */ 257 @SuppressWarnings("unchecked") 258 public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double"); 259 260 /** 261 * Returns a string representation of the {@code double} 262 * argument. All characters mentioned below are ASCII characters. 263 * <ul> 264 * <li>If the argument is NaN, the result is the string 265 * "{@code NaN}". 266 * <li>Otherwise, the result is a string that represents the sign and 267 * magnitude (absolute value) of the argument. If the sign is negative, 268 * the first character of the result is '{@code -}' 269 * ({@code '\u005Cu002D'}); if the sign is positive, no sign character 270 * appears in the result. As for the magnitude <i>m</i>: 271 * <ul> 272 * <li>If <i>m</i> is infinity, it is represented by the characters 273 * {@code "Infinity"}; thus, positive infinity produces the result 274 * {@code "Infinity"} and negative infinity produces the result 275 * {@code "-Infinity"}. 276 * 277 * <li>If <i>m</i> is zero, it is represented by the characters 278 * {@code "0.0"}; thus, negative zero produces the result 279 * {@code "-0.0"} and positive zero produces the result 280 * {@code "0.0"}. 281 * 282 * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less 283 * than 10<sup>7</sup>, then it is represented as the integer part of 284 * <i>m</i>, in decimal form with no leading zeroes, followed by 285 * '{@code .}' ({@code '\u005Cu002E'}), followed by one or 286 * more decimal digits representing the fractional part of <i>m</i>. 287 * 288 * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or 289 * equal to 10<sup>7</sup>, then it is represented in so-called 290 * "computerized scientific notation." Let <i>n</i> be the unique 291 * integer such that 10<sup><i>n</i></sup> ≤ <i>m</i> {@literal <} 292 * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the 293 * mathematically exact quotient of <i>m</i> and 294 * 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10. The 295 * magnitude is then represented as the integer part of <i>a</i>, 296 * as a single decimal digit, followed by '{@code .}' 297 * ({@code '\u005Cu002E'}), followed by decimal digits 298 * representing the fractional part of <i>a</i>, followed by the 299 * letter '{@code E}' ({@code '\u005Cu0045'}), followed 300 * by a representation of <i>n</i> as a decimal integer, as 301 * produced by the method {@link Integer#toString(int)}. 302 * </ul> 303 * </ul> 304 * How many digits must be printed for the fractional part of 305 * <i>m</i> or <i>a</i>? There must be at least one digit to represent 306 * the fractional part, and beyond that as many, but only as many, more 307 * digits as are needed to uniquely distinguish the argument value from 308 * adjacent values of type {@code double}. That is, suppose that 309 * <i>x</i> is the exact mathematical value represented by the decimal 310 * representation produced by this method for a finite nonzero argument 311 * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest 312 * to <i>x</i>; or if two {@code double} values are equally close 313 * to <i>x</i>, then <i>d</i> must be one of them and the least 314 * significant bit of the significand of <i>d</i> must be {@code 0}. 315 * 316 * <p>To create localized string representations of a floating-point 317 * value, use subclasses of {@link java.text.NumberFormat}. 318 * 319 * @param d the {@code double} to be converted. 320 * @return a string representation of the argument. 321 */ toString(double d)322 public static String toString(double d) { 323 return FloatingDecimal.toJavaFormatString(d); 324 } 325 326 /** 327 * Returns a hexadecimal string representation of the 328 * {@code double} argument. All characters mentioned below 329 * are ASCII characters. 330 * 331 * <ul> 332 * <li>If the argument is NaN, the result is the string 333 * "{@code NaN}". 334 * <li>Otherwise, the result is a string that represents the sign 335 * and magnitude of the argument. If the sign is negative, the 336 * first character of the result is '{@code -}' 337 * ({@code '\u005Cu002D'}); if the sign is positive, no sign 338 * character appears in the result. As for the magnitude <i>m</i>: 339 * 340 * <ul> 341 * <li>If <i>m</i> is infinity, it is represented by the string 342 * {@code "Infinity"}; thus, positive infinity produces the 343 * result {@code "Infinity"} and negative infinity produces 344 * the result {@code "-Infinity"}. 345 * 346 * <li>If <i>m</i> is zero, it is represented by the string 347 * {@code "0x0.0p0"}; thus, negative zero produces the result 348 * {@code "-0x0.0p0"} and positive zero produces the result 349 * {@code "0x0.0p0"}. 350 * 351 * <li>If <i>m</i> is a {@code double} value with a 352 * normalized representation, substrings are used to represent the 353 * significand and exponent fields. The significand is 354 * represented by the characters {@code "0x1."} 355 * followed by a lowercase hexadecimal representation of the rest 356 * of the significand as a fraction. Trailing zeros in the 357 * hexadecimal representation are removed unless all the digits 358 * are zero, in which case a single zero is used. Next, the 359 * exponent is represented by {@code "p"} followed 360 * by a decimal string of the unbiased exponent as if produced by 361 * a call to {@link Integer#toString(int) Integer.toString} on the 362 * exponent value. 363 * 364 * <li>If <i>m</i> is a {@code double} value with a subnormal 365 * representation, the significand is represented by the 366 * characters {@code "0x0."} followed by a 367 * hexadecimal representation of the rest of the significand as a 368 * fraction. Trailing zeros in the hexadecimal representation are 369 * removed. Next, the exponent is represented by 370 * {@code "p-1022"}. Note that there must be at 371 * least one nonzero digit in a subnormal significand. 372 * 373 * </ul> 374 * 375 * </ul> 376 * 377 * <table class="striped"> 378 * <caption>Examples</caption> 379 * <thead> 380 * <tr><th scope="col">Floating-point Value</th><th scope="col">Hexadecimal String</th> 381 * </thead> 382 * <tbody style="text-align:right"> 383 * <tr><th scope="row">{@code 1.0}</th> <td>{@code 0x1.0p0}</td> 384 * <tr><th scope="row">{@code -1.0}</th> <td>{@code -0x1.0p0}</td> 385 * <tr><th scope="row">{@code 2.0}</th> <td>{@code 0x1.0p1}</td> 386 * <tr><th scope="row">{@code 3.0}</th> <td>{@code 0x1.8p1}</td> 387 * <tr><th scope="row">{@code 0.5}</th> <td>{@code 0x1.0p-1}</td> 388 * <tr><th scope="row">{@code 0.25}</th> <td>{@code 0x1.0p-2}</td> 389 * <tr><th scope="row">{@code Double.MAX_VALUE}</th> 390 * <td>{@code 0x1.fffffffffffffp1023}</td> 391 * <tr><th scope="row">{@code Minimum Normal Value}</th> 392 * <td>{@code 0x1.0p-1022}</td> 393 * <tr><th scope="row">{@code Maximum Subnormal Value}</th> 394 * <td>{@code 0x0.fffffffffffffp-1022}</td> 395 * <tr><th scope="row">{@code Double.MIN_VALUE}</th> 396 * <td>{@code 0x0.0000000000001p-1022}</td> 397 * </tbody> 398 * </table> 399 * @param d the {@code double} to be converted. 400 * @return a hex string representation of the argument. 401 * @since 1.5 402 * @author Joseph D. Darcy 403 */ toHexString(double d)404 public static String toHexString(double d) { 405 /* 406 * Modeled after the "a" conversion specifier in C99, section 407 * 7.19.6.1; however, the output of this method is more 408 * tightly specified. 409 */ 410 if (!isFinite(d) ) 411 // For infinity and NaN, use the decimal output. 412 return Double.toString(d); 413 else { 414 // Initialized to maximum size of output. 415 StringBuilder answer = new StringBuilder(24); 416 417 if (Math.copySign(1.0, d) == -1.0) // value is negative, 418 answer.append("-"); // so append sign info 419 420 answer.append("0x"); 421 422 d = Math.abs(d); 423 424 if(d == 0.0) { 425 answer.append("0.0p0"); 426 } else { 427 boolean subnormal = (d < Double.MIN_NORMAL); 428 429 // Isolate significand bits and OR in a high-order bit 430 // so that the string representation has a known 431 // length. 432 long signifBits = (Double.doubleToLongBits(d) 433 & DoubleConsts.SIGNIF_BIT_MASK) | 434 0x1000000000000000L; 435 436 // Subnormal values have a 0 implicit bit; normal 437 // values have a 1 implicit bit. 438 answer.append(subnormal ? "0." : "1."); 439 440 // Isolate the low-order 13 digits of the hex 441 // representation. If all the digits are zero, 442 // replace with a single 0; otherwise, remove all 443 // trailing zeros. 444 String signif = Long.toHexString(signifBits).substring(3,16); 445 answer.append(signif.equals("0000000000000") ? // 13 zeros 446 "0": 447 signif.replaceFirst("0{1,12}$", "")); 448 449 answer.append('p'); 450 // If the value is subnormal, use the E_min exponent 451 // value for double; otherwise, extract and report d's 452 // exponent (the representation of a subnormal uses 453 // E_min -1). 454 answer.append(subnormal ? 455 Double.MIN_EXPONENT: 456 Math.getExponent(d)); 457 } 458 return answer.toString(); 459 } 460 } 461 462 /** 463 * Returns a {@code Double} object holding the 464 * {@code double} value represented by the argument string 465 * {@code s}. 466 * 467 * <p>If {@code s} is {@code null}, then a 468 * {@code NullPointerException} is thrown. 469 * 470 * <p>Leading and trailing whitespace characters in {@code s} 471 * are ignored. Whitespace is removed as if by the {@link 472 * String#trim} method; that is, both ASCII space and control 473 * characters are removed. The rest of {@code s} should 474 * constitute a <i>FloatValue</i> as described by the lexical 475 * syntax rules: 476 * 477 * <blockquote> 478 * <dl> 479 * <dt><i>FloatValue:</i> 480 * <dd><i>Sign<sub>opt</sub></i> {@code NaN} 481 * <dd><i>Sign<sub>opt</sub></i> {@code Infinity} 482 * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i> 483 * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i> 484 * <dd><i>SignedInteger</i> 485 * </dl> 486 * 487 * <dl> 488 * <dt><i>HexFloatingPointLiteral</i>: 489 * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i> 490 * </dl> 491 * 492 * <dl> 493 * <dt><i>HexSignificand:</i> 494 * <dd><i>HexNumeral</i> 495 * <dd><i>HexNumeral</i> {@code .} 496 * <dd>{@code 0x} <i>HexDigits<sub>opt</sub> 497 * </i>{@code .}<i> HexDigits</i> 498 * <dd>{@code 0X}<i> HexDigits<sub>opt</sub> 499 * </i>{@code .} <i>HexDigits</i> 500 * </dl> 501 * 502 * <dl> 503 * <dt><i>BinaryExponent:</i> 504 * <dd><i>BinaryExponentIndicator SignedInteger</i> 505 * </dl> 506 * 507 * <dl> 508 * <dt><i>BinaryExponentIndicator:</i> 509 * <dd>{@code p} 510 * <dd>{@code P} 511 * </dl> 512 * 513 * </blockquote> 514 * 515 * where <i>Sign</i>, <i>FloatingPointLiteral</i>, 516 * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and 517 * <i>FloatTypeSuffix</i> are as defined in the lexical structure 518 * sections of 519 * <cite>The Java Language Specification</cite>, 520 * except that underscores are not accepted between digits. 521 * If {@code s} does not have the form of 522 * a <i>FloatValue</i>, then a {@code NumberFormatException} 523 * is thrown. Otherwise, {@code s} is regarded as 524 * representing an exact decimal value in the usual 525 * "computerized scientific notation" or as an exact 526 * hexadecimal value; this exact numerical value is then 527 * conceptually converted to an "infinitely precise" 528 * binary value that is then rounded to type {@code double} 529 * by the usual round-to-nearest rule of IEEE 754 floating-point 530 * arithmetic, which includes preserving the sign of a zero 531 * value. 532 * 533 * Note that the round-to-nearest rule also implies overflow and 534 * underflow behaviour; if the exact value of {@code s} is large 535 * enough in magnitude (greater than or equal to ({@link 536 * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2), 537 * rounding to {@code double} will result in an infinity and if the 538 * exact value of {@code s} is small enough in magnitude (less 539 * than or equal to {@link #MIN_VALUE}/2), rounding to float will 540 * result in a zero. 541 * 542 * Finally, after rounding a {@code Double} object representing 543 * this {@code double} value is returned. 544 * 545 * <p> To interpret localized string representations of a 546 * floating-point value, use subclasses of {@link 547 * java.text.NumberFormat}. 548 * 549 * <p>Note that trailing format specifiers, specifiers that 550 * determine the type of a floating-point literal 551 * ({@code 1.0f} is a {@code float} value; 552 * {@code 1.0d} is a {@code double} value), do 553 * <em>not</em> influence the results of this method. In other 554 * words, the numerical value of the input string is converted 555 * directly to the target floating-point type. The two-step 556 * sequence of conversions, string to {@code float} followed 557 * by {@code float} to {@code double}, is <em>not</em> 558 * equivalent to converting a string directly to 559 * {@code double}. For example, the {@code float} 560 * literal {@code 0.1f} is equal to the {@code double} 561 * value {@code 0.10000000149011612}; the {@code float} 562 * literal {@code 0.1f} represents a different numerical 563 * value than the {@code double} literal 564 * {@code 0.1}. (The numerical value 0.1 cannot be exactly 565 * represented in a binary floating-point number.) 566 * 567 * <p>To avoid calling this method on an invalid string and having 568 * a {@code NumberFormatException} be thrown, the regular 569 * expression below can be used to screen the input string: 570 * 571 * <pre>{@code 572 * final String Digits = "(\\p{Digit}+)"; 573 * final String HexDigits = "(\\p{XDigit}+)"; 574 * // an exponent is 'e' or 'E' followed by an optionally 575 * // signed decimal integer. 576 * final String Exp = "[eE][+-]?"+Digits; 577 * final String fpRegex = 578 * ("[\\x00-\\x20]*"+ // Optional leading "whitespace" 579 * "[+-]?(" + // Optional sign character 580 * "NaN|" + // "NaN" string 581 * "Infinity|" + // "Infinity" string 582 * 583 * // A decimal floating-point string representing a finite positive 584 * // number without a leading sign has at most five basic pieces: 585 * // Digits . Digits ExponentPart FloatTypeSuffix 586 * // 587 * // Since this method allows integer-only strings as input 588 * // in addition to strings of floating-point literals, the 589 * // two sub-patterns below are simplifications of the grammar 590 * // productions from section 3.10.2 of 591 * // The Java Language Specification. 592 * 593 * // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt 594 * "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+ 595 * 596 * // . Digits ExponentPart_opt FloatTypeSuffix_opt 597 * "(\\.("+Digits+")("+Exp+")?)|"+ 598 * 599 * // Hexadecimal strings 600 * "((" + 601 * // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt 602 * "(0[xX]" + HexDigits + "(\\.)?)|" + 603 * 604 * // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt 605 * "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + 606 * 607 * ")[pP][+-]?" + Digits + "))" + 608 * "[fFdD]?))" + 609 * "[\\x00-\\x20]*");// Optional trailing "whitespace" 610 * 611 * if (Pattern.matches(fpRegex, myString)) 612 * Double.valueOf(myString); // Will not throw NumberFormatException 613 * else { 614 * // Perform suitable alternative action 615 * } 616 * }</pre> 617 * 618 * @param s the string to be parsed. 619 * @return a {@code Double} object holding the value 620 * represented by the {@code String} argument. 621 * @throws NumberFormatException if the string does not contain a 622 * parsable number. 623 */ valueOf(String s)624 public static Double valueOf(String s) throws NumberFormatException { 625 return new Double(parseDouble(s)); 626 } 627 628 /** 629 * Returns a {@code Double} instance representing the specified 630 * {@code double} value. 631 * If a new {@code Double} instance is not required, this method 632 * should generally be used in preference to the constructor 633 * {@link #Double(double)}, as this method is likely to yield 634 * significantly better space and time performance by caching 635 * frequently requested values. 636 * 637 * @param d a double value. 638 * @return a {@code Double} instance representing {@code d}. 639 * @since 1.5 640 */ 641 @IntrinsicCandidate valueOf(double d)642 public static Double valueOf(double d) { 643 return new Double(d); 644 } 645 646 /** 647 * Returns a new {@code double} initialized to the value 648 * represented by the specified {@code String}, as performed 649 * by the {@code valueOf} method of class 650 * {@code Double}. 651 * 652 * @param s the string to be parsed. 653 * @return the {@code double} value represented by the string 654 * argument. 655 * @throws NullPointerException if the string is null 656 * @throws NumberFormatException if the string does not contain 657 * a parsable {@code double}. 658 * @see java.lang.Double#valueOf(String) 659 * @since 1.2 660 */ parseDouble(String s)661 public static double parseDouble(String s) throws NumberFormatException { 662 return FloatingDecimal.parseDouble(s); 663 } 664 665 /** 666 * Returns {@code true} if the specified number is a 667 * Not-a-Number (NaN) value, {@code false} otherwise. 668 * 669 * @param v the value to be tested. 670 * @return {@code true} if the value of the argument is NaN; 671 * {@code false} otherwise. 672 */ isNaN(double v)673 public static boolean isNaN(double v) { 674 return (v != v); 675 } 676 677 /** 678 * Returns {@code true} if the specified number is infinitely 679 * large in magnitude, {@code false} otherwise. 680 * 681 * @param v the value to be tested. 682 * @return {@code true} if the value of the argument is positive 683 * infinity or negative infinity; {@code false} otherwise. 684 */ isInfinite(double v)685 public static boolean isInfinite(double v) { 686 return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY); 687 } 688 689 /** 690 * Returns {@code true} if the argument is a finite floating-point 691 * value; returns {@code false} otherwise (for NaN and infinity 692 * arguments). 693 * 694 * @param d the {@code double} value to be tested 695 * @return {@code true} if the argument is a finite 696 * floating-point value, {@code false} otherwise. 697 * @since 1.8 698 */ isFinite(double d)699 public static boolean isFinite(double d) { 700 return Math.abs(d) <= Double.MAX_VALUE; 701 } 702 703 /** 704 * The value of the Double. 705 * 706 * @serial 707 */ 708 private final double value; 709 710 /** 711 * Constructs a newly allocated {@code Double} object that 712 * represents the primitive {@code double} argument. 713 * 714 * @param value the value to be represented by the {@code Double}. 715 * 716 * @deprecated 717 * It is rarely appropriate to use this constructor. The static factory 718 * {@link #valueOf(double)} is generally a better choice, as it is 719 * likely to yield significantly better space and time performance. 720 */ 721 // Android-changed: not yet forRemoval on Android. 722 @Deprecated(since="9"/*, forRemoval = true*/) Double(double value)723 public Double(double value) { 724 this.value = value; 725 } 726 727 /** 728 * Constructs a newly allocated {@code Double} object that 729 * represents the floating-point value of type {@code double} 730 * represented by the string. The string is converted to a 731 * {@code double} value as if by the {@code valueOf} method. 732 * 733 * @param s a string to be converted to a {@code Double}. 734 * @throws NumberFormatException if the string does not contain a 735 * parsable number. 736 * 737 * @deprecated 738 * It is rarely appropriate to use this constructor. 739 * Use {@link #parseDouble(String)} to convert a string to a 740 * {@code double} primitive, or use {@link #valueOf(String)} 741 * to convert a string to a {@code Double} object. 742 */ 743 // Android-changed: not yet forRemoval on Android. 744 @Deprecated(since="9"/*, forRemoval = true */) Double(String s)745 public Double(String s) throws NumberFormatException { 746 value = parseDouble(s); 747 } 748 749 /** 750 * Returns {@code true} if this {@code Double} value is 751 * a Not-a-Number (NaN), {@code false} otherwise. 752 * 753 * @return {@code true} if the value represented by this object is 754 * NaN; {@code false} otherwise. 755 */ isNaN()756 public boolean isNaN() { 757 return isNaN(value); 758 } 759 760 /** 761 * Returns {@code true} if this {@code Double} value is 762 * infinitely large in magnitude, {@code false} otherwise. 763 * 764 * @return {@code true} if the value represented by this object is 765 * positive infinity or negative infinity; 766 * {@code false} otherwise. 767 */ isInfinite()768 public boolean isInfinite() { 769 return isInfinite(value); 770 } 771 772 /** 773 * Returns a string representation of this {@code Double} object. 774 * The primitive {@code double} value represented by this 775 * object is converted to a string exactly as if by the method 776 * {@code toString} of one argument. 777 * 778 * @return a {@code String} representation of this object. 779 * @see java.lang.Double#toString(double) 780 */ toString()781 public String toString() { 782 return toString(value); 783 } 784 785 /** 786 * Returns the value of this {@code Double} as a {@code byte} 787 * after a narrowing primitive conversion. 788 * 789 * @return the {@code double} value represented by this object 790 * converted to type {@code byte} 791 * @jls 5.1.3 Narrowing Primitive Conversion 792 * @since 1.1 793 */ byteValue()794 public byte byteValue() { 795 return (byte)value; 796 } 797 798 /** 799 * Returns the value of this {@code Double} as a {@code short} 800 * after a narrowing primitive conversion. 801 * 802 * @return the {@code double} value represented by this object 803 * converted to type {@code short} 804 * @jls 5.1.3 Narrowing Primitive Conversion 805 * @since 1.1 806 */ shortValue()807 public short shortValue() { 808 return (short)value; 809 } 810 811 /** 812 * Returns the value of this {@code Double} as an {@code int} 813 * after a narrowing primitive conversion. 814 * @jls 5.1.3 Narrowing Primitive Conversion 815 * 816 * @return the {@code double} value represented by this object 817 * converted to type {@code int} 818 */ intValue()819 public int intValue() { 820 return (int)value; 821 } 822 823 /** 824 * Returns the value of this {@code Double} as a {@code long} 825 * after a narrowing primitive conversion. 826 * 827 * @return the {@code double} value represented by this object 828 * converted to type {@code long} 829 * @jls 5.1.3 Narrowing Primitive Conversion 830 */ longValue()831 public long longValue() { 832 return (long)value; 833 } 834 835 /** 836 * Returns the value of this {@code Double} as a {@code float} 837 * after a narrowing primitive conversion. 838 * 839 * @return the {@code double} value represented by this object 840 * converted to type {@code float} 841 * @jls 5.1.3 Narrowing Primitive Conversion 842 * @since 1.0 843 */ floatValue()844 public float floatValue() { 845 return (float)value; 846 } 847 848 /** 849 * Returns the {@code double} value of this {@code Double} object. 850 * 851 * @return the {@code double} value represented by this object 852 */ 853 @IntrinsicCandidate doubleValue()854 public double doubleValue() { 855 return value; 856 } 857 858 /** 859 * Returns a hash code for this {@code Double} object. The 860 * result is the exclusive OR of the two halves of the 861 * {@code long} integer bit representation, exactly as 862 * produced by the method {@link #doubleToLongBits(double)}, of 863 * the primitive {@code double} value represented by this 864 * {@code Double} object. That is, the hash code is the value 865 * of the expression: 866 * 867 * <blockquote> 868 * {@code (int)(v^(v>>>32))} 869 * </blockquote> 870 * 871 * where {@code v} is defined by: 872 * 873 * <blockquote> 874 * {@code long v = Double.doubleToLongBits(this.doubleValue());} 875 * </blockquote> 876 * 877 * @return a {@code hash code} value for this object. 878 */ 879 @Override hashCode()880 public int hashCode() { 881 return Double.hashCode(value); 882 } 883 884 /** 885 * Returns a hash code for a {@code double} value; compatible with 886 * {@code Double.hashCode()}. 887 * 888 * @param value the value to hash 889 * @return a hash code value for a {@code double} value. 890 * @since 1.8 891 */ hashCode(double value)892 public static int hashCode(double value) { 893 long bits = doubleToLongBits(value); 894 return (int)(bits ^ (bits >>> 32)); 895 } 896 897 /** 898 * Compares this object against the specified object. The result 899 * is {@code true} if and only if the argument is not 900 * {@code null} and is a {@code Double} object that 901 * represents a {@code double} that has the same value as the 902 * {@code double} represented by this object. For this 903 * purpose, two {@code double} values are considered to be 904 * the same if and only if the method {@link 905 * #doubleToLongBits(double)} returns the identical 906 * {@code long} value when applied to each. 907 * 908 * @apiNote 909 * This method is defined in terms of {@link 910 * #doubleToLongBits(double)} rather than the {@code ==} operator 911 * on {@code double} values since the {@code ==} operator does 912 * <em>not</em> define an equivalence relation and to satisfy the 913 * {@linkplain Object#equals equals contract} an equivalence 914 * relation must be implemented; see <a 915 * href="#equivalenceRelation">this discussion</a> for details of 916 * floating-point equality and equivalence. 917 * 918 * @see java.lang.Double#doubleToLongBits(double) 919 * @jls 15.21.1 Numerical Equality Operators == and != 920 */ equals(Object obj)921 public boolean equals(Object obj) { 922 return (obj instanceof Double) 923 && (doubleToLongBits(((Double)obj).value) == 924 doubleToLongBits(value)); 925 } 926 927 /** 928 * Returns a representation of the specified floating-point value 929 * according to the IEEE 754 floating-point "double 930 * format" bit layout. 931 * 932 * <p>Bit 63 (the bit that is selected by the mask 933 * {@code 0x8000000000000000L}) represents the sign of the 934 * floating-point number. Bits 935 * 62-52 (the bits that are selected by the mask 936 * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0 937 * (the bits that are selected by the mask 938 * {@code 0x000fffffffffffffL}) represent the significand 939 * (sometimes called the mantissa) of the floating-point number. 940 * 941 * <p>If the argument is positive infinity, the result is 942 * {@code 0x7ff0000000000000L}. 943 * 944 * <p>If the argument is negative infinity, the result is 945 * {@code 0xfff0000000000000L}. 946 * 947 * <p>If the argument is NaN, the result is 948 * {@code 0x7ff8000000000000L}. 949 * 950 * <p>In all cases, the result is a {@code long} integer that, when 951 * given to the {@link #longBitsToDouble(long)} method, will produce a 952 * floating-point value the same as the argument to 953 * {@code doubleToLongBits} (except all NaN values are 954 * collapsed to a single "canonical" NaN value). 955 * 956 * @param value a {@code double} precision floating-point number. 957 * @return the bits that represent the floating-point number. 958 */ 959 @IntrinsicCandidate doubleToLongBits(double value)960 public static long doubleToLongBits(double value) { 961 if (!isNaN(value)) { 962 return doubleToRawLongBits(value); 963 } 964 return 0x7ff8000000000000L; 965 } 966 967 /** 968 * Returns a representation of the specified floating-point value 969 * according to the IEEE 754 floating-point "double 970 * format" bit layout, preserving Not-a-Number (NaN) values. 971 * 972 * <p>Bit 63 (the bit that is selected by the mask 973 * {@code 0x8000000000000000L}) represents the sign of the 974 * floating-point number. Bits 975 * 62-52 (the bits that are selected by the mask 976 * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0 977 * (the bits that are selected by the mask 978 * {@code 0x000fffffffffffffL}) represent the significand 979 * (sometimes called the mantissa) of the floating-point number. 980 * 981 * <p>If the argument is positive infinity, the result is 982 * {@code 0x7ff0000000000000L}. 983 * 984 * <p>If the argument is negative infinity, the result is 985 * {@code 0xfff0000000000000L}. 986 * 987 * <p>If the argument is NaN, the result is the {@code long} 988 * integer representing the actual NaN value. Unlike the 989 * {@code doubleToLongBits} method, 990 * {@code doubleToRawLongBits} does not collapse all the bit 991 * patterns encoding a NaN to a single "canonical" NaN 992 * value. 993 * 994 * <p>In all cases, the result is a {@code long} integer that, 995 * when given to the {@link #longBitsToDouble(long)} method, will 996 * produce a floating-point value the same as the argument to 997 * {@code doubleToRawLongBits}. 998 * 999 * @param value a {@code double} precision floating-point number. 1000 * @return the bits that represent the floating-point number. 1001 * @since 1.3 1002 */ 1003 @IntrinsicCandidate doubleToRawLongBits(double value)1004 public static native long doubleToRawLongBits(double value); 1005 1006 /** 1007 * Returns the {@code double} value corresponding to a given 1008 * bit representation. 1009 * The argument is considered to be a representation of a 1010 * floating-point value according to the IEEE 754 floating-point 1011 * "double format" bit layout. 1012 * 1013 * <p>If the argument is {@code 0x7ff0000000000000L}, the result 1014 * is positive infinity. 1015 * 1016 * <p>If the argument is {@code 0xfff0000000000000L}, the result 1017 * is negative infinity. 1018 * 1019 * <p>If the argument is any value in the range 1020 * {@code 0x7ff0000000000001L} through 1021 * {@code 0x7fffffffffffffffL} or in the range 1022 * {@code 0xfff0000000000001L} through 1023 * {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE 1024 * 754 floating-point operation provided by Java can distinguish 1025 * between two NaN values of the same type with different bit 1026 * patterns. Distinct values of NaN are only distinguishable by 1027 * use of the {@code Double.doubleToRawLongBits} method. 1028 * 1029 * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three 1030 * values that can be computed from the argument: 1031 * 1032 * <blockquote><pre>{@code 1033 * int s = ((bits >> 63) == 0) ? 1 : -1; 1034 * int e = (int)((bits >> 52) & 0x7ffL); 1035 * long m = (e == 0) ? 1036 * (bits & 0xfffffffffffffL) << 1 : 1037 * (bits & 0xfffffffffffffL) | 0x10000000000000L; 1038 * }</pre></blockquote> 1039 * 1040 * Then the floating-point result equals the value of the mathematical 1041 * expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-1075</sup>. 1042 * 1043 * <p>Note that this method may not be able to return a 1044 * {@code double} NaN with exactly same bit pattern as the 1045 * {@code long} argument. IEEE 754 distinguishes between two 1046 * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The 1047 * differences between the two kinds of NaN are generally not 1048 * visible in Java. Arithmetic operations on signaling NaNs turn 1049 * them into quiet NaNs with a different, but often similar, bit 1050 * pattern. However, on some processors merely copying a 1051 * signaling NaN also performs that conversion. In particular, 1052 * copying a signaling NaN to return it to the calling method 1053 * may perform this conversion. So {@code longBitsToDouble} 1054 * may not be able to return a {@code double} with a 1055 * signaling NaN bit pattern. Consequently, for some 1056 * {@code long} values, 1057 * {@code doubleToRawLongBits(longBitsToDouble(start))} may 1058 * <i>not</i> equal {@code start}. Moreover, which 1059 * particular bit patterns represent signaling NaNs is platform 1060 * dependent; although all NaN bit patterns, quiet or signaling, 1061 * must be in the NaN range identified above. 1062 * 1063 * @param bits any {@code long} integer. 1064 * @return the {@code double} floating-point value with the same 1065 * bit pattern. 1066 */ 1067 @IntrinsicCandidate longBitsToDouble(long bits)1068 public static native double longBitsToDouble(long bits); 1069 1070 /** 1071 * Compares two {@code Double} objects numerically. 1072 * 1073 * This method imposes a total order on {@code Double} objects 1074 * with two differences compared to the incomplete order defined by 1075 * the Java language numerical comparison operators ({@code <, <=, 1076 * ==, >=, >}) on {@code double} values. 1077 * 1078 * <ul><li> A NaN is <em>unordered</em> with respect to other 1079 * values and unequal to itself under the comparison 1080 * operators. This method chooses to define {@code 1081 * Double.NaN} to be equal to itself and greater than all 1082 * other {@code double} values (including {@code 1083 * Double.POSITIVE_INFINITY}). 1084 * 1085 * <li> Positive zero and negative zero compare equal 1086 * numerically, but are distinct and distinguishable values. 1087 * This method chooses to define positive zero ({@code +0.0d}), 1088 * to be greater than negative zero ({@code -0.0d}). 1089 * </ul> 1090 1091 * This ensures that the <i>natural ordering</i> of {@code Double} 1092 * objects imposed by this method is <i>consistent with 1093 * equals</i>; see <a href="#equivalenceRelation">this 1094 * discussion</a> for details of floating-point comparison and 1095 * ordering. 1096 * 1097 * @param anotherDouble the {@code Double} to be compared. 1098 * @return the value {@code 0} if {@code anotherDouble} is 1099 * numerically equal to this {@code Double}; a value 1100 * less than {@code 0} if this {@code Double} 1101 * is numerically less than {@code anotherDouble}; 1102 * and a value greater than {@code 0} if this 1103 * {@code Double} is numerically greater than 1104 * {@code anotherDouble}. 1105 * 1106 * @jls 15.20.1 Numerical Comparison Operators {@code <}, {@code <=}, {@code >}, and {@code >=} 1107 * @since 1.2 1108 */ compareTo(Double anotherDouble)1109 public int compareTo(Double anotherDouble) { 1110 return Double.compare(value, anotherDouble.value); 1111 } 1112 1113 /** 1114 * Compares the two specified {@code double} values. The sign 1115 * of the integer value returned is the same as that of the 1116 * integer that would be returned by the call: 1117 * <pre> 1118 * new Double(d1).compareTo(new Double(d2)) 1119 * </pre> 1120 * 1121 * @param d1 the first {@code double} to compare 1122 * @param d2 the second {@code double} to compare 1123 * @return the value {@code 0} if {@code d1} is 1124 * numerically equal to {@code d2}; a value less than 1125 * {@code 0} if {@code d1} is numerically less than 1126 * {@code d2}; and a value greater than {@code 0} 1127 * if {@code d1} is numerically greater than 1128 * {@code d2}. 1129 * @since 1.4 1130 */ compare(double d1, double d2)1131 public static int compare(double d1, double d2) { 1132 if (d1 < d2) 1133 return -1; // Neither val is NaN, thisVal is smaller 1134 if (d1 > d2) 1135 return 1; // Neither val is NaN, thisVal is larger 1136 1137 // Cannot use doubleToRawLongBits because of possibility of NaNs. 1138 long thisBits = Double.doubleToLongBits(d1); 1139 long anotherBits = Double.doubleToLongBits(d2); 1140 1141 return (thisBits == anotherBits ? 0 : // Values are equal 1142 (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN) 1143 1)); // (0.0, -0.0) or (NaN, !NaN) 1144 } 1145 1146 /** 1147 * Adds two {@code double} values together as per the + operator. 1148 * 1149 * @param a the first operand 1150 * @param b the second operand 1151 * @return the sum of {@code a} and {@code b} 1152 * @jls 4.2.4 Floating-Point Operations 1153 * @see java.util.function.BinaryOperator 1154 * @since 1.8 1155 */ sum(double a, double b)1156 public static double sum(double a, double b) { 1157 return a + b; 1158 } 1159 1160 /** 1161 * Returns the greater of two {@code double} values 1162 * as if by calling {@link Math#max(double, double) Math.max}. 1163 * 1164 * @param a the first operand 1165 * @param b the second operand 1166 * @return the greater of {@code a} and {@code b} 1167 * @see java.util.function.BinaryOperator 1168 * @since 1.8 1169 */ max(double a, double b)1170 public static double max(double a, double b) { 1171 return Math.max(a, b); 1172 } 1173 1174 /** 1175 * Returns the smaller of two {@code double} values 1176 * as if by calling {@link Math#min(double, double) Math.min}. 1177 * 1178 * @param a the first operand 1179 * @param b the second operand 1180 * @return the smaller of {@code a} and {@code b}. 1181 * @see java.util.function.BinaryOperator 1182 * @since 1.8 1183 */ min(double a, double b)1184 public static double min(double a, double b) { 1185 return Math.min(a, b); 1186 } 1187 1188 /** 1189 * Returns an {@link Optional} containing the nominal descriptor for this 1190 * instance, which is the instance itself. 1191 * 1192 * @return an {@link Optional} describing the {@linkplain Double} instance 1193 * @since 12 1194 * @hide 1195 */ 1196 @Override describeConstable()1197 public Optional<Double> describeConstable() { 1198 return Optional.of(this); 1199 } 1200 1201 /** 1202 * Resolves this instance as a {@link ConstantDesc}, the result of which is 1203 * the instance itself. 1204 * 1205 * @param lookup ignored 1206 * @return the {@linkplain Double} instance 1207 * @since 12 1208 * @hide 1209 */ 1210 @Override resolveConstantDesc(MethodHandles.Lookup lookup)1211 public Double resolveConstantDesc(MethodHandles.Lookup lookup) { 1212 return this; 1213 } 1214 1215 /** use serialVersionUID from JDK 1.0.2 for interoperability */ 1216 @java.io.Serial 1217 private static final long serialVersionUID = -9172774392245257468L; 1218 } 1219