compareTo abstract method
- numother
override
Compares this toother.
Returns a negative number ifthis is less thanother, zero if they areequal, and a positive number ifthis is greater thanother.
The ordering represented by this method is a total ordering ofnumvalues. All distinct doubles are non-equal, as are all distinct integers,but integers are equal to doubles if they have the same numericalvalue.
For doubles, thecompareTo operation is different from the partialordering given byoperator==,operator< andoperator>. For example,IEEE doubles impose that0.0 == -0.0 and all comparison operations onNaN return false.
This function imposes a complete ordering for doubles. When usingcompareTo, the following properties hold:
- All NaN values are considered equal, and greater than any numeric value.
- -0.0 is less than 0.0 (and the integer 0), but greater than any non-zeronegative value.
- Negative infinity is less than all other values and positive infinity isgreater than all non-NaN values.
- All other values are compared using their numeric value.
Examples:
print(1.compareTo(2)); // => -1print(2.compareTo(1)); // => 1print(1.compareTo(1)); // => 0// The following comparisons yield different results than the// corresponding comparison operators.print((-0.0).compareTo(0.0)); // => -1print(double.nan.compareTo(double.nan)); // => 0print(double.infinity.compareTo(double.nan)); // => -1// -0.0, and NaN comparison operators have rules imposed by the IEEE// standard.print(-0.0 == 0.0); // => trueprint(double.nan == double.nan); // => falseprint(double.infinity < double.nan); // => falseprint(double.nan < double.infinity); // => falseprint(double.nan == double.infinity); // => falseImplementation
int compareTo(num other);