Instance Method

squareRoot()

Returns the square root of the value, rounded to a representable value.

Declaration

func squareRoot() -> Double

Return Value

The square root of the value.

Discussion

The following example declares a function that calculates the length of the hypotenuse of a right triangle given its two perpendicular sides.

func hypotenuse(_ a: Double, _ b: Double) -> Double {
    return (a * a + b * b).squareRoot()
}

let (dx, dy) = (3.0, 4.0)
let distance = hypotenuse(dx, dy)
// distance == 5.0

See Also

Performing Calculations

Floating-Point Operators for Double

Perform arithmetic and bitwise operations or compare values.

func addingProduct(Double, Double) -> Double

Returns the result of adding the product of the two given values to this value, computed without intermediate rounding.

func addProduct(Double, Double)

Adds the product of the two given values to this value in place, computed without intermediate rounding.

func formSquareRoot()

Replaces this value with its square root, rounded to a representable value.

func remainder(dividingBy: Double) -> Double

Returns the remainder of this value divided by the given value.

func formRemainder(dividingBy: Double)

Replaces this value with the remainder of itself divided by the given value.

func truncatingRemainder(dividingBy: Double) -> Double

Returns the remainder of this value divided by the given value using truncating division.

func formTruncatingRemainder(dividingBy: Double)

Replaces this value with the remainder of itself divided by the given value using truncating division.

func negate()

Replaces this value with its additive inverse.