Aracılığıyla paylaş


Double.CompareTo(Double) Method

Definition

Compares two Double objects numerically.

[Android.Runtime.Register("compareTo", "(Ljava/lang/Double;)I", "")]
public int CompareTo (Java.Lang.Double anotherDouble);
[<Android.Runtime.Register("compareTo", "(Ljava/lang/Double;)I", "")>]
member this.CompareTo : Java.Lang.Double -> int

Parameters

anotherDouble
Double

the Double to be compared.

Returns

the value 0 if anotherDouble is numerically equal to this Double; a value less than 0 if this Double is numerically less than anotherDouble; and a value greater than 0 if this Double is numerically greater than anotherDouble.

Attributes

Exceptions

if object is null.

Remarks

Compares two Double objects numerically.

This method imposes a total order on Double objects with two differences compared to the incomplete order defined by the Java language numerical comparison operators (<, <=, ==, >=, >) on double values.

<ul><li> A NaN is <em>unordered</em> with respect to other values and unequal to itself under the comparison operators. This method chooses to define Double.NaN to be equal to itself and greater than all other double values (including Double.POSITIVE_INFINITY).

<li> Positive zero and negative zero compare equal numerically, but are distinct and distinguishable values. This method chooses to define positive zero (+0.0d), to be greater than negative zero (-0.0d). </ul>

This ensures that the natural ordering of Double objects imposed by this method is consistent with equals; see this discussion for details of floating-point comparison and ordering.

Added in 1.2.

Java documentation for java.lang.Double.compareTo(java.lang.Double).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also