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

# vDSP_distancesq

Calculates the single-precision distance squared between two points in n-dimensional space.

```
extern void vDSP_distancesq(const float *__A, vDSP_Stride __IA, const float *__B, vDSP_Stride __IB, float *__C, vDSP_Length __N);
```

## Parameters

`__A`

A vector that contains the coordinates of the first point.

`__IA`

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

`__B`

A vector that contains the coordinates of the second point.

`__IB`

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

`__C`

On output, the square of the Euclidean distance between the two points.

`__N`

The number of elements to process.

## Discussion

This function calculates the sum of squares of the differences of corresponding elements of vectors `A` and `B`, using the following operation:

```objc
C[0] = sum((A[n] - B[n]) ** 2, 0 <= n < N); 
```

For example, the following code calculates the distance squared between the two four-dimensional points `pointA` and `pointB`:

```swift
    let stride = 1
    
    let pointA: [Float] = [-1, 0, -2, 1]
    let pointB: [Float] = [ 2, 1,  4, 3]
    
    var distanceSquared = Float()
    
    vDSP_distancesq(pointA, stride,
                    pointB, stride,
                    &distanceSquared,
                    vDSP_Length(pointA.count))
    
    print("distance²", distanceSquared) // Prints "distance² 50.0"
```

---

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)