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

# vDSP_distancesqD

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

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

## Parameters

`__A`

An array that contains the coordinates of the first point.

`__IA`

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

`__B`

An array 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: [Double] = [-1, 0, -2, 1]
    let pointB: [Double] = [ 2, 1,  4, 3]
    
    var distanceSquared = Double()
    
    vDSP_distancesqD(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)