Function

vDSP_vpythgD(_:_:_:_:_:_:_:_:_:_:_:)

Calculates the double-precision hypotenuse of N triangles.

Declaration

func vDSP_vpythgD(_ __A: UnsafePointer<Double>, _ __IA: vDSP_Stride, _ __B: UnsafePointer<Double>, _ __IB: vDSP_Stride, _ __C: UnsafePointer<Double>, _ __IC: vDSP_Stride, _ __D: UnsafePointer<Double>, _ __ID: vDSP_Stride, _ __E: UnsafeMutablePointer<Double>, _ __IE: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Double-precision real input vector.

__IA

Stride for A.

__B

Double-precision real input vector.

__IB

Stride for B.

__C

Double-precision real input vector.

__IC

Stride for C.

__D

Double-precision real input vector.

__ID

Stride for D.

__E

Double-precision real output vector.

__IE

Stride for E.

__N

The number of elements to process.

Discussion

The vDSP_vpythg(_:_:_:_:_:_:_:_:_:_:_:) and vDSP_vpythgD(_:_:_:_:_:_:_:_:_:_:_:) functions return the length of the hypotenuse of N number of triangles. The differences between corresponding elements of vectors A and C, and B and D define the lengths of the two legs of each triangle.

The functions use the following operation:

for (n = 0; n < N; ++n)
    E[n] = sqrt((A[n]-C[n])**2 + (B[n]-D[n])**2);

For example, the following code specifies a series of lengths of the two legs (that is, the sides adjacent to the right angle) of a series of triangles:

let a: [Float] = [3,  5,  8,  7, 20, 12,  9]
let b: [Float] = [4, 12, 15, 24, 21, 35, 40]

let c: [Float] = [0]
let d: [Float] = [0]

Use vDSP_vpythg(_:_:_:_:_:_:_:_:_:_:_:) to calculate the lengths of the hypotenuses:

let n = vDSP_Length(a.count)

let stride = vDSP_Stride(1)

var e = [Float](repeating: 0, count: a.count)

vDSP_vpythg(a, stride,
            b, stride,
            c, stride,
            d, stride,
            &e, stride,
            n)

// Prints "[5.0, 13.0, 17.0, 25.0, 29.0, 37.0, 41.0]"
print(e)

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software