---
title: "distanceSquared(_:_:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/vdsp/distancesquared(_:_:)-2dvb6"
---

# distanceSquared(_:_:)

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

## Declaration

```swift
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

Discussion This function calculates the sum of squares of the differences of corresponding elements of vectors A and B, using the following operation: 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:     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".

## See Also

### Type Methods

- [absolute(_:)](accelerate/vdsp/absolute(_:)-9c3ge.md)
- [absolute(_:)](accelerate/vdsp/absolute(_:)-5ehc1.md)
- [absolute(_:result:)](accelerate/vdsp/absolute(_:result:)-9x5jn.md)
- [absolute(_:result:)](accelerate/vdsp/absolute(_:result:)-1wu9x.md)
- [absolute(_:result:)](accelerate/vdsp/absolute(_:result:)-657bd.md)
- [absolute(_:result:)](accelerate/vdsp/absolute(_:result:)-4pigo.md)
- [add(_:_:)](accelerate/vdsp/add(_:_:)-9mv1a.md)
- [add(_:_:)](accelerate/vdsp/add(_:_:)-2ftxc.md)
- [add(_:_:)](accelerate/vdsp/add(_:_:)-53nh9.md)
- [add(_:_:)](accelerate/vdsp/add(_:_:)-7swvf.md)
- [add(_:_:result:)](accelerate/vdsp/add(_:_:result:)-2531u.md)
- [add(_:_:result:)](accelerate/vdsp/add(_:_:result:)-2w0o9.md)
- [add(_:_:result:)](accelerate/vdsp/add(_:_:result:)-338hl.md)
- [add(_:_:result:)](accelerate/vdsp/add(_:_:result:)-3vzwi.md)
- [add(_:to:count:result:)](accelerate/vdsp/add(_:to:count:result:)-g1dk.md)
