Float.hx 30 KB

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