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] |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 * - NaN is equal to itself, and greater than any numeric value. |
Lasse Reichstein Nielsen
2016/11/29 15:59:21
- All NaN values are considered equal, and greater
floitsch
2016/12/02 01:26:56
Done.
| |
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 * - Positive infinity is greater than any finite value (any value apart from | |
Lasse Reichstein Nielsen
2016/11/29 15:59:21
any negative value and any finite positive value
floitsch
2016/12/02 01:26:56
Done.
| |
81 * itself and NaN), and negative infinity is less than any other value. | |
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 operations yield different results than their | |
Lasse Reichstein Nielsen
2016/11/29 15:59:21
operations -> comparisons (it's unclear what the "
floitsch
2016/12/02 01:26:56
Done.
| |
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 result = double.parse(source, _returnDoubleNull); | 468 result = double.parse(source, _returnDoubleNull); |
445 if (result != null) return result; | 469 if (result != null) return result; |
446 if (onError == null) throw new FormatException(input); | 470 if (onError == null) throw new FormatException(input); |
447 return onError(input); | 471 return onError(input); |
448 } | 472 } |
449 | 473 |
450 /** Helper functions for [parse]. */ | 474 /** Helper functions for [parse]. */ |
451 static int _returnIntNull(String _) => null; | 475 static int _returnIntNull(String _) => null; |
452 static double _returnDoubleNull(String _) => null; | 476 static double _returnDoubleNull(String _) => null; |
453 } | 477 } |
OLD | NEW |