Double.hx 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. package java.lang;
  2. /*
  3. * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /**
  27. * The {@code Double} class wraps a value of the primitive type
  28. * {@code double} in an object. An object of type
  29. * {@code Double} contains a single field whose type is
  30. * {@code double}.
  31. *
  32. * <p>In addition, this class provides several methods for converting a
  33. * {@code double} to a {@code String} and a
  34. * {@code String} to a {@code double}, as well as other
  35. * constants and methods useful when dealing with a
  36. * {@code double}.
  37. *
  38. * @author Lee Boynton
  39. * @author Arthur van Hoff
  40. * @author Joseph D. Darcy
  41. * @since JDK1.0
  42. */
  43. @:require(java0) extern class Double extends java.lang.Number implements java.lang.Comparable<Double>
  44. {
  45. /**
  46. * A constant holding the positive infinity of type
  47. * {@code double}. It is equal to the value returned by
  48. * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  49. */
  50. public static var POSITIVE_INFINITY(default, null) : Float;
  51. /**
  52. * A constant holding the negative infinity of type
  53. * {@code double}. It is equal to the value returned by
  54. * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  55. */
  56. public static var NEGATIVE_INFINITY(default, null) : Float;
  57. /**
  58. * A constant holding a Not-a-Number (NaN) value of type
  59. * {@code double}. It is equivalent to the value returned by
  60. * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  61. */
  62. public static var NaN(default, null) : Float;
  63. /**
  64. * A constant holding the largest positive finite value of type
  65. * {@code double},
  66. * (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>. It is equal to
  67. * the hexadecimal floating-point literal
  68. * {@code 0x1.fffffffffffffP+1023} and also equal to
  69. * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
  70. */
  71. public static var MAX_VALUE(default, null) : Float;
  72. /**
  73. * A constant holding the smallest positive normal value of type
  74. * {@code double}, 2<sup>-1022</sup>. It is equal to the
  75. * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
  76. * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
  77. *
  78. * @since 1.6
  79. */
  80. @:require(java6) public static var MIN_NORMAL(default, null) : Float;
  81. /**
  82. * A constant holding the smallest positive nonzero value of type
  83. * {@code double}, 2<sup>-1074</sup>. It is equal to the
  84. * hexadecimal floating-point literal
  85. * {@code 0x0.0000000000001P-1022} and also equal to
  86. * {@code Double.longBitsToDouble(0x1L)}.
  87. */
  88. public static var MIN_VALUE(default, null) : Float;
  89. /**
  90. * Maximum exponent a finite {@code double} variable may have.
  91. * It is equal to the value returned by
  92. * {@code Math.getExponent(Double.MAX_VALUE)}.
  93. *
  94. * @since 1.6
  95. */
  96. @:require(java6) public static var MAX_EXPONENT(default, null) : Int;
  97. /**
  98. * Minimum exponent a normalized {@code double} variable may
  99. * have. It is equal to the value returned by
  100. * {@code Math.getExponent(Double.MIN_NORMAL)}.
  101. *
  102. * @since 1.6
  103. */
  104. @:require(java6) public static var MIN_EXPONENT(default, null) : Int;
  105. /**
  106. * The number of bits used to represent a {@code double} value.
  107. *
  108. * @since 1.5
  109. */
  110. @:require(java5) public static var SIZE(default, null) : Int;
  111. /**
  112. * The {@code Class} instance representing the primitive type
  113. * {@code double}.
  114. *
  115. * @since JDK1.1
  116. */
  117. @:require(java1) public static var TYPE(default, null) : Class<Double>;
  118. /**
  119. * Returns a string representation of the {@code double}
  120. * argument. All characters mentioned below are ASCII characters.
  121. * <ul>
  122. * <li>If the argument is NaN, the result is the string
  123. * "{@code NaN}".
  124. * <li>Otherwise, the result is a string that represents the sign and
  125. * magnitude (absolute value) of the argument. If the sign is negative,
  126. * the first character of the result is '{@code -}'
  127. * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
  128. * appears in the result. As for the magnitude <i>m</i>:
  129. * <ul>
  130. * <li>If <i>m</i> is infinity, it is represented by the characters
  131. * {@code "Infinity"}; thus, positive infinity produces the result
  132. * {@code "Infinity"} and negative infinity produces the result
  133. * {@code "-Infinity"}.
  134. *
  135. * <li>If <i>m</i> is zero, it is represented by the characters
  136. * {@code "0.0"}; thus, negative zero produces the result
  137. * {@code "-0.0"} and positive zero produces the result
  138. * {@code "0.0"}.
  139. *
  140. * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
  141. * than 10<sup>7</sup>, then it is represented as the integer part of
  142. * <i>m</i>, in decimal form with no leading zeroes, followed by
  143. * '{@code .}' (<code>'&#92;u002E'</code>), followed by one or
  144. * more decimal digits representing the fractional part of <i>m</i>.
  145. *
  146. * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
  147. * equal to 10<sup>7</sup>, then it is represented in so-called
  148. * "computerized scientific notation." Let <i>n</i> be the unique
  149. * integer such that 10<sup><i>n</i></sup> &le; <i>m</i> {@literal <}
  150. * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
  151. * mathematically exact quotient of <i>m</i> and
  152. * 10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10. The
  153. * magnitude is then represented as the integer part of <i>a</i>,
  154. * as a single decimal digit, followed by '{@code .}'
  155. * (<code>'&#92;u002E'</code>), followed by decimal digits
  156. * representing the fractional part of <i>a</i>, followed by the
  157. * letter '{@code E}' (<code>'&#92;u0045'</code>), followed
  158. * by a representation of <i>n</i> as a decimal integer, as
  159. * produced by the method {@link Integer#toString(int)}.
  160. * </ul>
  161. * </ul>
  162. * How many digits must be printed for the fractional part of
  163. * <i>m</i> or <i>a</i>? There must be at least one digit to represent
  164. * the fractional part, and beyond that as many, but only as many, more
  165. * digits as are needed to uniquely distinguish the argument value from
  166. * adjacent values of type {@code double}. That is, suppose that
  167. * <i>x</i> is the exact mathematical value represented by the decimal
  168. * representation produced by this method for a finite nonzero argument
  169. * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
  170. * to <i>x</i>; or if two {@code double} values are equally close
  171. * to <i>x</i>, then <i>d</i> must be one of them and the least
  172. * significant bit of the significand of <i>d</i> must be {@code 0}.
  173. *
  174. * <p>To create localized string representations of a floating-point
  175. * value, use subclasses of {@link java.text.NumberFormat}.
  176. *
  177. * @param d the {@code double} to be converted.
  178. * @return a string representation of the argument.
  179. */
  180. @:native('toString') @:overload public static function _toString(d : Float) : String;
  181. /**
  182. * Returns a hexadecimal string representation of the
  183. * {@code double} argument. All characters mentioned below
  184. * are ASCII characters.
  185. *
  186. * <ul>
  187. * <li>If the argument is NaN, the result is the string
  188. * "{@code NaN}".
  189. * <li>Otherwise, the result is a string that represents the sign
  190. * and magnitude of the argument. If the sign is negative, the
  191. * first character of the result is '{@code -}'
  192. * (<code>'&#92;u002D'</code>); if the sign is positive, no sign
  193. * character appears in the result. As for the magnitude <i>m</i>:
  194. *
  195. * <ul>
  196. * <li>If <i>m</i> is infinity, it is represented by the string
  197. * {@code "Infinity"}; thus, positive infinity produces the
  198. * result {@code "Infinity"} and negative infinity produces
  199. * the result {@code "-Infinity"}.
  200. *
  201. * <li>If <i>m</i> is zero, it is represented by the string
  202. * {@code "0x0.0p0"}; thus, negative zero produces the result
  203. * {@code "-0x0.0p0"} and positive zero produces the result
  204. * {@code "0x0.0p0"}.
  205. *
  206. * <li>If <i>m</i> is a {@code double} value with a
  207. * normalized representation, substrings are used to represent the
  208. * significand and exponent fields. The significand is
  209. * represented by the characters {@code "0x1."}
  210. * followed by a lowercase hexadecimal representation of the rest
  211. * of the significand as a fraction. Trailing zeros in the
  212. * hexadecimal representation are removed unless all the digits
  213. * are zero, in which case a single zero is used. Next, the
  214. * exponent is represented by {@code "p"} followed
  215. * by a decimal string of the unbiased exponent as if produced by
  216. * a call to {@link Integer#toString(int) Integer.toString} on the
  217. * exponent value.
  218. *
  219. * <li>If <i>m</i> is a {@code double} value with a subnormal
  220. * representation, the significand is represented by the
  221. * characters {@code "0x0."} followed by a
  222. * hexadecimal representation of the rest of the significand as a
  223. * fraction. Trailing zeros in the hexadecimal representation are
  224. * removed. Next, the exponent is represented by
  225. * {@code "p-1022"}. Note that there must be at
  226. * least one nonzero digit in a subnormal significand.
  227. *
  228. * </ul>
  229. *
  230. * </ul>
  231. *
  232. * <table border>
  233. * <caption><h3>Examples</h3></caption>
  234. * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
  235. * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
  236. * <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td>
  237. * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
  238. * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
  239. * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
  240. * <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td>
  241. * <tr><td>{@code Double.MAX_VALUE}</td>
  242. * <td>{@code 0x1.fffffffffffffp1023}</td>
  243. * <tr><td>{@code Minimum Normal Value}</td>
  244. * <td>{@code 0x1.0p-1022}</td>
  245. * <tr><td>{@code Maximum Subnormal Value}</td>
  246. * <td>{@code 0x0.fffffffffffffp-1022}</td>
  247. * <tr><td>{@code Double.MIN_VALUE}</td>
  248. * <td>{@code 0x0.0000000000001p-1022}</td>
  249. * </table>
  250. * @param d the {@code double} to be converted.
  251. * @return a hex string representation of the argument.
  252. * @since 1.5
  253. * @author Joseph D. Darcy
  254. */
  255. @:require(java5) @:overload public static function toHexString(d : Float) : String;
  256. /**
  257. * Returns a {@code Double} object holding the
  258. * {@code double} value represented by the argument string
  259. * {@code s}.
  260. *
  261. * <p>If {@code s} is {@code null}, then a
  262. * {@code NullPointerException} is thrown.
  263. *
  264. * <p>Leading and trailing whitespace characters in {@code s}
  265. * are ignored. Whitespace is removed as if by the {@link
  266. * String#trim} method; that is, both ASCII space and control
  267. * characters are removed. The rest of {@code s} should
  268. * constitute a <i>FloatValue</i> as described by the lexical
  269. * syntax rules:
  270. *
  271. * <blockquote>
  272. * <dl>
  273. * <dt><i>FloatValue:</i>
  274. * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
  275. * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
  276. * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
  277. * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
  278. * <dd><i>SignedInteger</i>
  279. * </dl>
  280. *
  281. * <p>
  282. *
  283. * <dl>
  284. * <dt><i>HexFloatingPointLiteral</i>:
  285. * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
  286. * </dl>
  287. *
  288. * <p>
  289. *
  290. * <dl>
  291. * <dt><i>HexSignificand:</i>
  292. * <dd><i>HexNumeral</i>
  293. * <dd><i>HexNumeral</i> {@code .}
  294. * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
  295. * </i>{@code .}<i> HexDigits</i>
  296. * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
  297. * </i>{@code .} <i>HexDigits</i>
  298. * </dl>
  299. *
  300. * <p>
  301. *
  302. * <dl>
  303. * <dt><i>BinaryExponent:</i>
  304. * <dd><i>BinaryExponentIndicator SignedInteger</i>
  305. * </dl>
  306. *
  307. * <p>
  308. *
  309. * <dl>
  310. * <dt><i>BinaryExponentIndicator:</i>
  311. * <dd>{@code p}
  312. * <dd>{@code P}
  313. * </dl>
  314. *
  315. * </blockquote>
  316. *
  317. * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
  318. * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
  319. * <i>FloatTypeSuffix</i> are as defined in the lexical structure
  320. * sections of
  321. * <cite>The Java&trade; Language Specification</cite>,
  322. * except that underscores are not accepted between digits.
  323. * If {@code s} does not have the form of
  324. * a <i>FloatValue</i>, then a {@code NumberFormatException}
  325. * is thrown. Otherwise, {@code s} is regarded as
  326. * representing an exact decimal value in the usual
  327. * "computerized scientific notation" or as an exact
  328. * hexadecimal value; this exact numerical value is then
  329. * conceptually converted to an "infinitely precise"
  330. * binary value that is then rounded to type {@code double}
  331. * by the usual round-to-nearest rule of IEEE 754 floating-point
  332. * arithmetic, which includes preserving the sign of a zero
  333. * value.
  334. *
  335. * Note that the round-to-nearest rule also implies overflow and
  336. * underflow behaviour; if the exact value of {@code s} is large
  337. * enough in magnitude (greater than or equal to ({@link
  338. * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
  339. * rounding to {@code double} will result in an infinity and if the
  340. * exact value of {@code s} is small enough in magnitude (less
  341. * than or equal to {@link #MIN_VALUE}/2), rounding to float will
  342. * result in a zero.
  343. *
  344. * Finally, after rounding a {@code Double} object representing
  345. * this {@code double} value is returned.
  346. *
  347. * <p> To interpret localized string representations of a
  348. * floating-point value, use subclasses of {@link
  349. * java.text.NumberFormat}.
  350. *
  351. * <p>Note that trailing format specifiers, specifiers that
  352. * determine the type of a floating-point literal
  353. * ({@code 1.0f} is a {@code float} value;
  354. * {@code 1.0d} is a {@code double} value), do
  355. * <em>not</em> influence the results of this method. In other
  356. * words, the numerical value of the input string is converted
  357. * directly to the target floating-point type. The two-step
  358. * sequence of conversions, string to {@code float} followed
  359. * by {@code float} to {@code double}, is <em>not</em>
  360. * equivalent to converting a string directly to
  361. * {@code double}. For example, the {@code float}
  362. * literal {@code 0.1f} is equal to the {@code double}
  363. * value {@code 0.10000000149011612}; the {@code float}
  364. * literal {@code 0.1f} represents a different numerical
  365. * value than the {@code double} literal
  366. * {@code 0.1}. (The numerical value 0.1 cannot be exactly
  367. * represented in a binary floating-point number.)
  368. *
  369. * <p>To avoid calling this method on an invalid string and having
  370. * a {@code NumberFormatException} be thrown, the regular
  371. * expression below can be used to screen the input string:
  372. *
  373. * <code>
  374. * <pre>
  375. * final String Digits = "(\\p{Digit}+)";
  376. * final String HexDigits = "(\\p{XDigit}+)";
  377. * // an exponent is 'e' or 'E' followed by an optionally
  378. * // signed decimal integer.
  379. * final String Exp = "[eE][+-]?"+Digits;
  380. * final String fpRegex =
  381. * ("[\\x00-\\x20]*"+ // Optional leading "whitespace"
  382. * "[+-]?(" + // Optional sign character
  383. * "NaN|" + // "NaN" string
  384. * "Infinity|" + // "Infinity" string
  385. *
  386. * // A decimal floating-point string representing a finite positive
  387. * // number without a leading sign has at most five basic pieces:
  388. * // Digits . Digits ExponentPart FloatTypeSuffix
  389. * //
  390. * // Since this method allows integer-only strings as input
  391. * // in addition to strings of floating-point literals, the
  392. * // two sub-patterns below are simplifications of the grammar
  393. * // productions from section 3.10.2 of
  394. * // <cite>The Java&trade; Language Specification</cite>.
  395. *
  396. * // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
  397. * "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
  398. *
  399. * // . Digits ExponentPart_opt FloatTypeSuffix_opt
  400. * "(\\.("+Digits+")("+Exp+")?)|"+
  401. *
  402. * // Hexadecimal strings
  403. * "((" +
  404. * // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
  405. * "(0[xX]" + HexDigits + "(\\.)?)|" +
  406. *
  407. * // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
  408. * "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
  409. *
  410. * ")[pP][+-]?" + Digits + "))" +
  411. * "[fFdD]?))" +
  412. * "[\\x00-\\x20]*");// Optional trailing "whitespace"
  413. *
  414. * if (Pattern.matches(fpRegex, myString))
  415. * Double.valueOf(myString); // Will not throw NumberFormatException
  416. * else {
  417. * // Perform suitable alternative action
  418. * }
  419. * </pre>
  420. * </code>
  421. *
  422. * @param s the string to be parsed.
  423. * @return a {@code Double} object holding the value
  424. * represented by the {@code String} argument.
  425. * @throws NumberFormatException if the string does not contain a
  426. * parsable number.
  427. */
  428. @:overload public static function valueOf(s : String) : Double;
  429. /**
  430. * Returns a {@code Double} instance representing the specified
  431. * {@code double} value.
  432. * If a new {@code Double} instance is not required, this method
  433. * should generally be used in preference to the constructor
  434. * {@link #Double(double)}, as this method is likely to yield
  435. * significantly better space and time performance by caching
  436. * frequently requested values.
  437. *
  438. * @param d a double value.
  439. * @return a {@code Double} instance representing {@code d}.
  440. * @since 1.5
  441. */
  442. @:require(java5) @:overload public static function valueOf(d : Float) : Double;
  443. /**
  444. * Returns a new {@code double} initialized to the value
  445. * represented by the specified {@code String}, as performed
  446. * by the {@code valueOf} method of class
  447. * {@code Double}.
  448. *
  449. * @param s the string to be parsed.
  450. * @return the {@code double} value represented by the string
  451. * argument.
  452. * @throws NullPointerException if the string is null
  453. * @throws NumberFormatException if the string does not contain
  454. * a parsable {@code double}.
  455. * @see java.lang.Double#valueOf(String)
  456. * @since 1.2
  457. */
  458. @:require(java2) @:overload public static function parseDouble(s : String) : Float;
  459. /**
  460. * Returns {@code true} if the specified number is a
  461. * Not-a-Number (NaN) value, {@code false} otherwise.
  462. *
  463. * @param v the value to be tested.
  464. * @return {@code true} if the value of the argument is NaN;
  465. * {@code false} otherwise.
  466. */
  467. @:native('isNaN') @:overload public static function _isNaN(v : Float) : Bool;
  468. /**
  469. * Returns {@code true} if the specified number is infinitely
  470. * large in magnitude, {@code false} otherwise.
  471. *
  472. * @param v the value to be tested.
  473. * @return {@code true} if the value of the argument is positive
  474. * infinity or negative infinity; {@code false} otherwise.
  475. */
  476. @:native('isInfinite') @:overload public static function _isInfinite(v : Float) : Bool;
  477. /**
  478. * Constructs a newly allocated {@code Double} object that
  479. * represents the primitive {@code double} argument.
  480. *
  481. * @param value the value to be represented by the {@code Double}.
  482. */
  483. @:overload public function new(value : Float) : Void;
  484. /**
  485. * Constructs a newly allocated {@code Double} object that
  486. * represents the floating-point value of type {@code double}
  487. * represented by the string. The string is converted to a
  488. * {@code double} value as if by the {@code valueOf} method.
  489. *
  490. * @param s a string to be converted to a {@code Double}.
  491. * @throws NumberFormatException if the string does not contain a
  492. * parsable number.
  493. * @see java.lang.Double#valueOf(java.lang.String)
  494. */
  495. @:overload public function new(s : String) : Void;
  496. /**
  497. * Returns {@code true} if this {@code Double} value is
  498. * a Not-a-Number (NaN), {@code false} otherwise.
  499. *
  500. * @return {@code true} if the value represented by this object is
  501. * NaN; {@code false} otherwise.
  502. */
  503. @:overload public function isNaN() : Bool;
  504. /**
  505. * Returns {@code true} if this {@code Double} value is
  506. * infinitely large in magnitude, {@code false} otherwise.
  507. *
  508. * @return {@code true} if the value represented by this object is
  509. * positive infinity or negative infinity;
  510. * {@code false} otherwise.
  511. */
  512. @:overload public function isInfinite() : Bool;
  513. /**
  514. * Returns a string representation of this {@code Double} object.
  515. * The primitive {@code double} value represented by this
  516. * object is converted to a string exactly as if by the method
  517. * {@code toString} of one argument.
  518. *
  519. * @return a {@code String} representation of this object.
  520. * @see java.lang.Double#toString(double)
  521. */
  522. @:overload public function toString() : String;
  523. /**
  524. * Returns the value of this {@code Double} as a {@code byte} (by
  525. * casting to a {@code byte}).
  526. *
  527. * @return the {@code double} value represented by this object
  528. * converted to type {@code byte}
  529. * @since JDK1.1
  530. */
  531. @:require(java1) @:overload override public function byteValue() : java.StdTypes.Int8;
  532. /**
  533. * Returns the value of this {@code Double} as a
  534. * {@code short} (by casting to a {@code short}).
  535. *
  536. * @return the {@code double} value represented by this object
  537. * converted to type {@code short}
  538. * @since JDK1.1
  539. */
  540. @:require(java1) @:overload override public function shortValue() : java.StdTypes.Int16;
  541. /**
  542. * Returns the value of this {@code Double} as an
  543. * {@code int} (by casting to type {@code int}).
  544. *
  545. * @return the {@code double} value represented by this object
  546. * converted to type {@code int}
  547. */
  548. @:overload override public function intValue() : Int;
  549. /**
  550. * Returns the value of this {@code Double} as a
  551. * {@code long} (by casting to type {@code long}).
  552. *
  553. * @return the {@code double} value represented by this object
  554. * converted to type {@code long}
  555. */
  556. @:overload override public function longValue() : haxe.Int64;
  557. /**
  558. * Returns the {@code float} value of this
  559. * {@code Double} object.
  560. *
  561. * @return the {@code double} value represented by this object
  562. * converted to type {@code float}
  563. * @since JDK1.0
  564. */
  565. @:require(java0) @:overload override public function floatValue() : Single;
  566. /**
  567. * Returns the {@code double} value of this
  568. * {@code Double} object.
  569. *
  570. * @return the {@code double} value represented by this object
  571. */
  572. @:overload override public function doubleValue() : Float;
  573. /**
  574. * Returns a hash code for this {@code Double} object. The
  575. * result is the exclusive OR of the two halves of the
  576. * {@code long} integer bit representation, exactly as
  577. * produced by the method {@link #doubleToLongBits(double)}, of
  578. * the primitive {@code double} value represented by this
  579. * {@code Double} object. That is, the hash code is the value
  580. * of the expression:
  581. *
  582. * <blockquote>
  583. * {@code (int)(v^(v>>>32))}
  584. * </blockquote>
  585. *
  586. * where {@code v} is defined by:
  587. *
  588. * <blockquote>
  589. * {@code long v = Double.doubleToLongBits(this.doubleValue());}
  590. * </blockquote>
  591. *
  592. * @return a {@code hash code} value for this object.
  593. */
  594. @:overload public function hashCode() : Int;
  595. /**
  596. * Compares this object against the specified object. The result
  597. * is {@code true} if and only if the argument is not
  598. * {@code null} and is a {@code Double} object that
  599. * represents a {@code double} that has the same value as the
  600. * {@code double} represented by this object. For this
  601. * purpose, two {@code double} values are considered to be
  602. * the same if and only if the method {@link
  603. * #doubleToLongBits(double)} returns the identical
  604. * {@code long} value when applied to each.
  605. *
  606. * <p>Note that in most cases, for two instances of class
  607. * {@code Double}, {@code d1} and {@code d2}, the
  608. * value of {@code d1.equals(d2)} is {@code true} if and
  609. * only if
  610. *
  611. * <blockquote>
  612. * {@code d1.doubleValue() == d2.doubleValue()}
  613. * </blockquote>
  614. *
  615. * <p>also has the value {@code true}. However, there are two
  616. * exceptions:
  617. * <ul>
  618. * <li>If {@code d1} and {@code d2} both represent
  619. * {@code Double.NaN}, then the {@code equals} method
  620. * returns {@code true}, even though
  621. * {@code Double.NaN==Double.NaN} has the value
  622. * {@code false}.
  623. * <li>If {@code d1} represents {@code +0.0} while
  624. * {@code d2} represents {@code -0.0}, or vice versa,
  625. * the {@code equal} test has the value {@code false},
  626. * even though {@code +0.0==-0.0} has the value {@code true}.
  627. * </ul>
  628. * This definition allows hash tables to operate properly.
  629. * @param obj the object to compare with.
  630. * @return {@code true} if the objects are the same;
  631. * {@code false} otherwise.
  632. * @see java.lang.Double#doubleToLongBits(double)
  633. */
  634. @:overload public function equals(obj : Dynamic) : Bool;
  635. /**
  636. * Returns a representation of the specified floating-point value
  637. * according to the IEEE 754 floating-point "double
  638. * format" bit layout.
  639. *
  640. * <p>Bit 63 (the bit that is selected by the mask
  641. * {@code 0x8000000000000000L}) represents the sign of the
  642. * floating-point number. Bits
  643. * 62-52 (the bits that are selected by the mask
  644. * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
  645. * (the bits that are selected by the mask
  646. * {@code 0x000fffffffffffffL}) represent the significand
  647. * (sometimes called the mantissa) of the floating-point number.
  648. *
  649. * <p>If the argument is positive infinity, the result is
  650. * {@code 0x7ff0000000000000L}.
  651. *
  652. * <p>If the argument is negative infinity, the result is
  653. * {@code 0xfff0000000000000L}.
  654. *
  655. * <p>If the argument is NaN, the result is
  656. * {@code 0x7ff8000000000000L}.
  657. *
  658. * <p>In all cases, the result is a {@code long} integer that, when
  659. * given to the {@link #longBitsToDouble(long)} method, will produce a
  660. * floating-point value the same as the argument to
  661. * {@code doubleToLongBits} (except all NaN values are
  662. * collapsed to a single "canonical" NaN value).
  663. *
  664. * @param value a {@code double} precision floating-point number.
  665. * @return the bits that represent the floating-point number.
  666. */
  667. @:overload public static function doubleToLongBits(value : Float) : haxe.Int64;
  668. /**
  669. * Returns a representation of the specified floating-point value
  670. * according to the IEEE 754 floating-point "double
  671. * format" bit layout, preserving Not-a-Number (NaN) values.
  672. *
  673. * <p>Bit 63 (the bit that is selected by the mask
  674. * {@code 0x8000000000000000L}) represents the sign of the
  675. * floating-point number. Bits
  676. * 62-52 (the bits that are selected by the mask
  677. * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
  678. * (the bits that are selected by the mask
  679. * {@code 0x000fffffffffffffL}) represent the significand
  680. * (sometimes called the mantissa) of the floating-point number.
  681. *
  682. * <p>If the argument is positive infinity, the result is
  683. * {@code 0x7ff0000000000000L}.
  684. *
  685. * <p>If the argument is negative infinity, the result is
  686. * {@code 0xfff0000000000000L}.
  687. *
  688. * <p>If the argument is NaN, the result is the {@code long}
  689. * integer representing the actual NaN value. Unlike the
  690. * {@code doubleToLongBits} method,
  691. * {@code doubleToRawLongBits} does not collapse all the bit
  692. * patterns encoding a NaN to a single "canonical" NaN
  693. * value.
  694. *
  695. * <p>In all cases, the result is a {@code long} integer that,
  696. * when given to the {@link #longBitsToDouble(long)} method, will
  697. * produce a floating-point value the same as the argument to
  698. * {@code doubleToRawLongBits}.
  699. *
  700. * @param value a {@code double} precision floating-point number.
  701. * @return the bits that represent the floating-point number.
  702. * @since 1.3
  703. */
  704. @:require(java3) @:overload @:native public static function doubleToRawLongBits(value : Float) : haxe.Int64;
  705. /**
  706. * Returns the {@code double} value corresponding to a given
  707. * bit representation.
  708. * The argument is considered to be a representation of a
  709. * floating-point value according to the IEEE 754 floating-point
  710. * "double format" bit layout.
  711. *
  712. * <p>If the argument is {@code 0x7ff0000000000000L}, the result
  713. * is positive infinity.
  714. *
  715. * <p>If the argument is {@code 0xfff0000000000000L}, the result
  716. * is negative infinity.
  717. *
  718. * <p>If the argument is any value in the range
  719. * {@code 0x7ff0000000000001L} through
  720. * {@code 0x7fffffffffffffffL} or in the range
  721. * {@code 0xfff0000000000001L} through
  722. * {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE
  723. * 754 floating-point operation provided by Java can distinguish
  724. * between two NaN values of the same type with different bit
  725. * patterns. Distinct values of NaN are only distinguishable by
  726. * use of the {@code Double.doubleToRawLongBits} method.
  727. *
  728. * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
  729. * values that can be computed from the argument:
  730. *
  731. * <blockquote><pre>
  732. * int s = ((bits &gt;&gt; 63) == 0) ? 1 : -1;
  733. * int e = (int)((bits &gt;&gt; 52) & 0x7ffL);
  734. * long m = (e == 0) ?
  735. * (bits & 0xfffffffffffffL) &lt;&lt; 1 :
  736. * (bits & 0xfffffffffffffL) | 0x10000000000000L;
  737. * </pre></blockquote>
  738. *
  739. * Then the floating-point result equals the value of the mathematical
  740. * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-1075</sup>.
  741. *
  742. * <p>Note that this method may not be able to return a
  743. * {@code double} NaN with exactly same bit pattern as the
  744. * {@code long} argument. IEEE 754 distinguishes between two
  745. * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The
  746. * differences between the two kinds of NaN are generally not
  747. * visible in Java. Arithmetic operations on signaling NaNs turn
  748. * them into quiet NaNs with a different, but often similar, bit
  749. * pattern. However, on some processors merely copying a
  750. * signaling NaN also performs that conversion. In particular,
  751. * copying a signaling NaN to return it to the calling method
  752. * may perform this conversion. So {@code longBitsToDouble}
  753. * may not be able to return a {@code double} with a
  754. * signaling NaN bit pattern. Consequently, for some
  755. * {@code long} values,
  756. * {@code doubleToRawLongBits(longBitsToDouble(start))} may
  757. * <i>not</i> equal {@code start}. Moreover, which
  758. * particular bit patterns represent signaling NaNs is platform
  759. * dependent; although all NaN bit patterns, quiet or signaling,
  760. * must be in the NaN range identified above.
  761. *
  762. * @param bits any {@code long} integer.
  763. * @return the {@code double} floating-point value with the same
  764. * bit pattern.
  765. */
  766. @:overload @:native public static function longBitsToDouble(bits : haxe.Int64) : Float;
  767. /**
  768. * Compares two {@code Double} objects numerically. There
  769. * are two ways in which comparisons performed by this method
  770. * differ from those performed by the Java language numerical
  771. * comparison operators ({@code <, <=, ==, >=, >})
  772. * when applied to primitive {@code double} values:
  773. * <ul><li>
  774. * {@code Double.NaN} is considered by this method
  775. * to be equal to itself and greater than all other
  776. * {@code double} values (including
  777. * {@code Double.POSITIVE_INFINITY}).
  778. * <li>
  779. * {@code 0.0d} is considered by this method to be greater
  780. * than {@code -0.0d}.
  781. * </ul>
  782. * This ensures that the <i>natural ordering</i> of
  783. * {@code Double} objects imposed by this method is <i>consistent
  784. * with equals</i>.
  785. *
  786. * @param anotherDouble the {@code Double} to be compared.
  787. * @return the value {@code 0} if {@code anotherDouble} is
  788. * numerically equal to this {@code Double}; a value
  789. * less than {@code 0} if this {@code Double}
  790. * is numerically less than {@code anotherDouble};
  791. * and a value greater than {@code 0} if this
  792. * {@code Double} is numerically greater than
  793. * {@code anotherDouble}.
  794. *
  795. * @since 1.2
  796. */
  797. @:require(java2) @:overload public function compareTo(anotherDouble : Double) : Int;
  798. /**
  799. * Compares the two specified {@code double} values. The sign
  800. * of the integer value returned is the same as that of the
  801. * integer that would be returned by the call:
  802. * <pre>
  803. * new Double(d1).compareTo(new Double(d2))
  804. * </pre>
  805. *
  806. * @param d1 the first {@code double} to compare
  807. * @param d2 the second {@code double} to compare
  808. * @return the value {@code 0} if {@code d1} is
  809. * numerically equal to {@code d2}; a value less than
  810. * {@code 0} if {@code d1} is numerically less than
  811. * {@code d2}; and a value greater than {@code 0}
  812. * if {@code d1} is numerically greater than
  813. * {@code d2}.
  814. * @since 1.4
  815. */
  816. @:require(java4) @:overload public static function compare(d1 : Float, d2 : Float) : Int;
  817. }