Contents

hypot(_:_:)

Returns the single-precision hypotenuses of right triangles with legs that are the lengths of corresponding elements of the two input vectors.

Declaration

static func hypot<U, V>(_ x: U, _ y: V) -> [Float] where U : AccelerateBuffer, V : AccelerateBuffer, U.Element == Float, V.Element == Float

Parameters

  • x:

    An array that contains the lengths of the first set of legs of the triangles.

  • y:

    An array that contains the lengths of the second set of legs of the triangles.

Discussion

This function returns the square roots of the sum of the squares of corresponding elements of vectors x and y, using the following operation:

for (n = 0; n < N; ++n)
    C[n] = sqrt(x[n]*x[n] + y[n]*y[n]);

For example, the following code calculates the hypotenuse of four Pythagorean triples:

    let x: [Float] = [3, 6, 5, 9]
    let y: [Float] = [4, 8, 12, 12]
    
    let hypotenuses = vDSP.hypot(x, y)
    
    // Prints "[5.0, 10.0, 13.0, 15.0]".
    print(hypotenuses)

See Also

Related Documentation

Type Methods