Instance Method

distance(to:)

Returns the distance from this value to the given value, expressed as a stride.

Declaration

func distance(to other: Float) -> Float

Parameters

other

The value to calculate the distance to.

Return Value

The distance from this value to other.

Discussion

If this type’s Stride type conforms to BinaryInteger, then for two values x and y, and a distance n = x.distance(to: y), x.advanced(by: n) == y. Using this method with types that have a noninteger Stride may result in an approximation.

Complexity: O(1)

Relationships

From Protocol

See Also

Infrequently Used Functionality

init()

Creates a value initialized to zero.

init(integerLiteral: Int64)

Creates an instance initialized to the specified integer value.

init(floatLiteral: Float)

Creates an instance initialized to the specified floating-point value.

init(integerLiteral: Float)

Creates an instance initialized to the specified integer value.

func advanced(by: Float) -> Float

Returns a value that is offset the specified distance from this value.

func write<Target>(to: inout Target)

Writes a textual representation of this instance into the given output stream.