Compares this to other
.
Returns a negative number if this
is less than other
, zero if they are equal, and a positive number if this
is greater than other
.
The ordering represented by this method is a total ordering of num values. All distinct doubles are non-equal, as are all distinct integers, but integers are equal to doubles if they have the same numerical value.
For doubles, the compareTo
operation is different from the partial ordering given by operator==, operator< and operator>. For example, IEEE doubles impose that 0.0 == -0.0
and all comparison operations on NaN return false.
This function imposes a complete ordering for doubles. When using compareTo
the following properties hold:
Examples:
print(1.compareTo(2)); // => -1 print(2.compareTo(1)); // => 1 print(1.compareTo(1)); // => 0 // The following comparisons yield different results than the // corresponding comparison operators. print((-0.0).compareTo(0.0)); // => -1 print(double.nan.compareTo(double.nan)); // => 0 print(double.infinity.compareTo(double.nan)); // => -1 // -0.0, and NaN comparison operators have rules imposed by the IEEE // standard. print(-0.0 == 0.0); // => true print(double.nan == double.nan); // => false print(double.infinity < double.nan); // => false print(double.nan < double.infinity); // => false print(double.nan == double.infinity); // => false
int compareTo(num other);
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/num/compareTo.html