<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/distanceSquared(_:_:)-2dvb6",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO15distanceSquaredySfx_q_tAA0A6BufferRzAA0a7MutableE0R_Sf7ElementRtzSfAGRt_r0_lFZ"
  },
  "title" : "distanceSquared(_:_:)"
}
-->

# distanceSquared(_:_:)

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

```
static func distanceSquared<U, V>(_ pointA: U, _ pointB: V) -> Float where U : AccelerateBuffer, V : AccelerateMutableBuffer, U.Element == Float, V.Element == Float
```

## Parameters

`pointA`

An array that contains the coordinates of the first point.

`pointB`

An array that contains the coordinates of the second point.

## 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 pointA: [Float] = [-1, 0, -2, 1]
    let pointB: [Float] = [ 2, 1,  4, 3]
    
    let distanceSquared = vDSP.distanceSquared(pointA, pointB)

    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)