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

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

Issue 2537813002: Update `num.compareTo` documentation. (Closed)
Patch Set: Address comments. Created 4 years 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
« no previous file with comments | « no previous file | 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]
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * Compares this to `other`. 59 * Compares this to `other`.
60 * 60 *
61 * Returns a negative number if `this` is less than `other`, zero if they are 61 * Returns a negative number if `this` is less than `other`, zero if they are
62 * equal, and a positive number if `this` is greater than `other`. 62 * equal, and a positive number if `this` is greater than `other`.
63 * 63 *
64 * The orderding represented by this method is a total ordering of [num] 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, 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 66 * but integers are equal to doubles if they have the same numerical
67 * value. 67 * value.
68 * 68 *
69 * For ordering, the double NaN value is considered equal to itself, and 69 * For doubles, the `compareTo` operation is different from the partial
70 * greater than any numeric value (unlike its behavior in `operator==`). 70 * ordering given by [operator==], [operator<] and [operator>]. For example,
71 * IEEE doubles impose that `0.0 == -0.0` and all comparison operations on
72 * NaN return false.
71 * 73 *
72 * The double value -0.0 is considered less than 0.0 (and the integer 0), but 74 * This function imposes a complete ordering for doubles. When using
73 * greater than any non-zero negative value. 75 * `compareTo` the following properties hold:
74 * 76 *
75 * Positive infinity is greater than any finite value (any value apart from 77 * - All NaN values are considered equal, and greater than any numeric value.
76 * itself and NaN), and negative infinity is less than any other value. 78 * - -0.0 is less than 0.0 (and the integer 0), but greater than any non-zero
79 * negative value.
80 * - Negative infinity is less than all other values and positive infinity is
81 * greater than all non-NaN values.
82 * - All other values are compared using their numeric value.
77 * 83 *
78 * All other values are compared using their numeric value. 84 * Examples:
85 * ```
86 * print(1.compareTo(2)); // => -1
87 * print(2.compareTo(1)); // => 1
88 * print(1.compareTo(1)); // => 0
89 *
90 * // The following comparisons yield different results than the
91 * // corresponding comparison operators.
92 * print((-0.0).compareTo(0.0)); // => -1
93 * print(double.NAN.compareTo(double.NAN)); // => 0
94 * print(double.INFINITY.compareTo(double.NAN)); // => -1
95 *
96 * // -0.0, and NaN comparison operators have rules imposed by the IEEE
97 * // standard.
98 * print(-0.0 == 0.0); // => true
99 * print(double.NAN == double.NAN); // => false
100 * print(double.INFINITY < double.NAN); // => false
101 * print(double.NAN < double.INFINITY); // => false
102 * print(double.NAN == double.INFINITY); // => false
79 */ 103 */
80 int compareTo(num other); 104 int compareTo(num other);
81 105
82 /** Addition operator. */ 106 /** Addition operator. */
83 num operator +(num other); 107 num operator +(num other);
84 108
85 /** Subtraction operator. */ 109 /** Subtraction operator. */
86 num operator -(num other); 110 num operator -(num other);
87 111
88 /** Multiplication operator. */ 112 /** Multiplication operator. */
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 result = double.parse(source, _returnDoubleNull); 471 result = double.parse(source, _returnDoubleNull);
448 if (result != null) return result; 472 if (result != null) return result;
449 if (onError == null) throw new FormatException(input); 473 if (onError == null) throw new FormatException(input);
450 return onError(input); 474 return onError(input);
451 } 475 }
452 476
453 /** Helper functions for [parse]. */ 477 /** Helper functions for [parse]. */
454 static int _returnIntNull(String _) => null; 478 static int _returnIntNull(String _) => null;
455 static double _returnDoubleNull(String _) => null; 479 static double _returnDoubleNull(String _) => null;
456 } 480 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698