Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An integer or floating-point number. | 8 * An integer or floating-point number. |
| 9 * | 9 * |
| 10 * It is a compile-time error for any type other than [int] or [double] | 10 * It is a compile-time error for any type other than [int] or [double] |
| 11 * to attempt to extend or implement num. | 11 * to attempt to extend or implement num. |
| 12 */ | 12 */ |
| 13 abstract class num implements Comparable<num> { | 13 abstract class num implements Comparable<num> { |
| 14 /** | |
| 15 * Test whether this value is numerically equal to `other`. | |
| 16 * | |
| 17 * If both operands are doubles, they are equal if they have the same | |
| 18 * representation, except that: | |
| 19 * * zero and minus zero (0.0 and -0.0) are considered equal. They | |
| 20 * both have the numerical value zero. | |
| 21 * * NaN is not equal to anything, including NaN. If either operand is | |
| 22 * NaN, the result is always false. | |
| 23 * | |
| 24 * If one operand is a double and the other is an int, they are equal if | |
| 25 * the double has an integer value (finite with no fractional part) and | |
| 26 * `identical(doubleValue.toInt(), intValue)`. | |
| 27 * | |
| 28 * If both operands are integers, they are equal if they have the same value. | |
| 29 * | |
| 30 * Returns false if `other` is not a [num]. | |
| 31 * | |
| 32 * Notice that the behavior for NaN is non-reflexive. This means that | |
| 33 * equality of double values is not a proper equality relation, as is | |
| 34 * otherwise required of `operator==`. Using NaN in, e.g., a [HashSet] | |
| 35 * will fail to work. The behavior is the standard IEEE-754 equality of | |
| 36 * doubles. | |
| 37 * | |
| 38 * If you can avoid NaN values, the reamining doubles do have a proper eqality | |
|
karlklose
2013/10/15 11:38:33
reamining -> remaining.
Lasse Reichstein Nielsen
2013/10/15 11:58:08
Done.
| |
| 39 * relation, and can be used safely. | |
| 40 * | |
| 41 * Use [compareTo] for a comparison that distinguishes zero and minus zero, | |
| 42 * and that considers NaN values as equal. | |
| 43 */ | |
| 44 bool operator==(Object other); | |
| 45 | |
| 46 /** | |
| 47 * Returns a hash code for a numerical value. | |
| 48 * | |
| 49 * The hash code is compatible with equality. It returns the same value | |
| 50 * for an [int] and a [double] with the same numerical value, and therefore | |
| 51 * the same value for the doubles zero and minus zero. | |
| 52 * | |
| 53 * No guarantees are made about the hash code of NaN. | |
| 54 */ | |
| 55 int get hashCode; | |
| 56 | |
| 57 /** | |
| 58 * Orders this value relative to `other`. | |
|
floitsch
2013/10/15 11:36:17
Why not simply "Compares `this` with [other]" ?
Lasse Reichstein Nielsen
2013/10/15 11:58:08
Works.
| |
| 59 * | |
| 60 * Returns a negative number if `this` is considered less than `other`, | |
|
floitsch
2013/10/15 11:36:17
-considered-
Lasse Reichstein Nielsen
2013/10/15 11:58:08
Removed, but this begs the question what it means
| |
| 61 * zero if they are considered equal, and a positive number if `this` is | |
|
floitsch
2013/10/15 11:36:17
-considered-
| |
| 62 * considered greater than `other`. | |
|
floitsch
2013/10/15 11:36:17
-considered-
| |
| 63 * | |
| 64 * The orderding represented by this method is a total ordering of [num] | |
| 65 * values. All distinct doubles are non-equal, as are all distinct integers, | |
| 66 * but integers are equal to doubles if they have the same numerical | |
| 67 * value. | |
| 68 * | |
| 69 * For ordering, the double NaN value is considered equal to itself, and | |
| 70 * greater than an numeric value (unlike its behavior in `operator==`). | |
| 71 * | |
| 72 * The double value -0.0 is considered less than 0.0 (and the integer 0), but | |
| 73 * greater than any non-zero negative value. | |
| 74 * | |
| 75 * Positive infinity is greater than any finite value (any value apart from | |
| 76 * itself and NaN), and negative infinity is less than any other value. | |
| 77 */ | |
| 78 int compareTo(num other); | |
| 79 | |
| 14 /** Addition operator. */ | 80 /** Addition operator. */ |
| 15 num operator +(num other); | 81 num operator +(num other); |
| 16 | 82 |
| 17 /** Subtraction operator. */ | 83 /** Subtraction operator. */ |
| 18 num operator -(num other); | 84 num operator -(num other); |
| 19 | 85 |
| 20 /** Multiplication operator. */ | 86 /** Multiplication operator. */ |
| 21 num operator *(num other); | 87 num operator *(num other); |
| 22 | 88 |
| 23 /** | 89 /** |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 * | 334 * |
| 269 * Note: the conversion may round the output if the returned string | 335 * Note: the conversion may round the output if the returned string |
| 270 * is accurate enough to uniquely identify the input-number. | 336 * is accurate enough to uniquely identify the input-number. |
| 271 * For example the most precise representation of the [double] `9e59` equals | 337 * For example the most precise representation of the [double] `9e59` equals |
| 272 * `"899999999999999918767229449717619953810131273674690656206848"`, but | 338 * `"899999999999999918767229449717619953810131273674690656206848"`, but |
| 273 * this method returns the shorter (but still uniquely identifying) `"9e59"`. | 339 * this method returns the shorter (but still uniquely identifying) `"9e59"`. |
| 274 * | 340 * |
| 275 */ | 341 */ |
| 276 String toString(); | 342 String toString(); |
| 277 } | 343 } |
| OLD | NEW |