Instance Method

isTotallyOrdered(belowOrEqualTo:)

Returns a Boolean value indicating whether this instance should precede or tie positions with the given value in an ascending sort.

Declaration

func isTotallyOrdered(belowOrEqualTo other: Double) -> Bool

Parameters

other

A floating-point value to compare to this value.

Return Value

true if this value is ordered below or the same as other in a total ordering of the floating-point type; otherwise, false.

Discussion

This relation is a refinement of the less-than-or-equal-to operator (<=) that provides a total order on all values of the type, including signed zeros and NaNs.

The following example uses isTotallyOrdered(belowOrEqualTo:) to sort an array of floating-point values, including some that are NaN:

var numbers = [2.5, 21.25, 3.0, .nan, -9.5]
numbers.sort { !$1.isTotallyOrdered(belowOrEqualTo: $0) }
// numbers == [-9.5, 2.5, 3.0, 21.25, NaN]

The isTotallyOrdered(belowOrEqualTo:) method implements the total order relation as defined by the IEEE 754 specification.

See Also

Comparing Values

Floating-Point Operators for Double

Perform arithmetic and bitwise operations or compare values.

func isEqual(to: Double) -> Bool

Returns a Boolean value indicating whether this instance is equal to the given value.

func isLess(than: Double) -> Bool

Returns a Boolean value indicating whether this instance is less than the given value.

func isLessThanOrEqualTo(Double) -> Bool

Returns a Boolean value indicating whether this instance is less than or equal to the given value.

static func minimum(Double, Double) -> Double

Returns the lesser of the two given values.

static func minimumMagnitude(Double, Double) -> Double

Returns the value with lesser magnitude.

static func maximum(Double, Double) -> Double

Returns the greater of the two given values.

static func maximumMagnitude(Double, Double) -> Double

Returns the value with greater magnitude.