Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: sdk/lib/core/num.dart

Issue 27302003: Document equality and compareTo of numbers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/double.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 remaining doubles do have a proper eqality
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 * Compares this to `other`.
59 *
60 * Returns a negative number if `this` is less than `other`, zero if they are
61 * equal, and a positive number if `this` is greater than `other`.
62 *
63 * The orderding represented by this method is a total ordering of [num]
64 * values. All distinct doubles are non-equal, as are all distinct integers,
65 * but integers are equal to doubles if they have the same numerical
66 * value.
67 *
68 * For ordering, the double NaN value is considered equal to itself, and
69 * greater than any numeric value (unlike its behavior in `operator==`).
70 *
71 * The double value -0.0 is considered less than 0.0 (and the integer 0), but
72 * greater than any non-zero negative value.
73 *
74 * Positive infinity is greater than any finite value (any value apart from
75 * itself and NaN), and negative infinity is less than any other value.
76 *
77 * All other values are compared using their numeric value.
78 */
79 int compareTo(num other);
80
14 /** Addition operator. */ 81 /** Addition operator. */
15 num operator +(num other); 82 num operator +(num other);
16 83
17 /** Subtraction operator. */ 84 /** Subtraction operator. */
18 num operator -(num other); 85 num operator -(num other);
19 86
20 /** Multiplication operator. */ 87 /** Multiplication operator. */
21 num operator *(num other); 88 num operator *(num other);
22 89
23 /** 90 /**
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 * 335 *
269 * Note: the conversion may round the output if the returned string 336 * Note: the conversion may round the output if the returned string
270 * is accurate enough to uniquely identify the input-number. 337 * is accurate enough to uniquely identify the input-number.
271 * For example the most precise representation of the [double] `9e59` equals 338 * For example the most precise representation of the [double] `9e59` equals
272 * `"899999999999999918767229449717619953810131273674690656206848"`, but 339 * `"899999999999999918767229449717619953810131273674690656206848"`, but
273 * this method returns the shorter (but still uniquely identifying) `"9e59"`. 340 * this method returns the shorter (but still uniquely identifying) `"9e59"`.
274 * 341 *
275 */ 342 */
276 String toString(); 343 String toString();
277 } 344 }
OLDNEW
« no previous file with comments | « runtime/lib/double.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698