<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP_vpythg",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@vDSP_vpythg"
  },
  "title" : "vDSP_vpythg"
}
-->

# vDSP_vpythg

Calculates the single-precision hypotenuses of right triangles with legs that are the differences of corresponding elements of two pairs of vectors.

```
extern void vDSP_vpythg(const float *__A, vDSP_Stride __IA, const float *__B, vDSP_Stride __IB, const float *__C, vDSP_Stride __IC, const float *__D, vDSP_Stride __ID, float *__E, vDSP_Stride __IE, vDSP_Length __N);
```

## Parameters

`__A`

A vector that contains the first values of the first set of legs of the triangles.

`__IA`

The distance between the elements in the input vector `A`.

`__B`

A vector that contains the second values of the first set of legs of the triangles.

`__IB`

The distance between the elements in the input vector `B`.

`__C`

A vector that contains the first values of the second set of legs of the triangles.

`__IC`

The distance between the elements in the input vector `C`.

`__D`

A vector that contains the second values of the second set of legs of the triangles.

`__ID`

The distance between the elements in the input vector `D`.

`__E`

A vector that receives the result of the calculation.

`__IE`

The distance between the elements in the output vector `E`.

`__N`

The number of elements to process.

## Discussion

This function calculates the length of the hypotenuse of *n* number of triangles, where *n* is the number of elements in the supplied vectors. The differences between corresponding elements of vectors `x0` and `x1` and vectors `y0` and `y1` define the lengths of the two legs of each triangle.

The functions use the following operation:

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

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

```swift
    let stride = 1
    
    let a: [Float] = [3, 6, 5, 9]
    let b: [Float] = [0, 0, 0, 0]
    
    let c: [Float] = [0, 0, 0, 0]
    let d: [Float] = [4, 8, 12, 12]
    
    let hypotenuses = [Float](
        unsafeUninitializedCapacity: a.count) {
            buffer, initializedCount in
            
            vDSP_vpythg(
                a, stride,
                b, stride,
                c, stride,
                d, stride,
                buffer.baseAddress!, stride,
                vDSP_Length(a.count)
            )
   
            initializedCount = a.count
        }
    
    // Prints "[5.0, 10.0, 13.0, 15.0]".
    print(hypotenuses)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)