Instance Method

distance(to:)

Returns the distance from this value to the specified value.

Declaration

func distance(to other: Float80) -> Float80

Parameters

other

A value to calculate the distance to.

Return Value

The distance between this value and other.

Discussion

For two values x and y, the result of x.distance(to: y) is equal to y - x—a distance d such that x.advanced(by: d) approximates y. For example:

let x = 21.5
let d = x.distance(to: 15.0)
// d == -6.5

print(x.advanced(by: d))
// Prints "15.0"

Relationships

From Protocol