<!--
{
  "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/sumAndSumOfSquares(_:)-45el",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO18sumAndSumOfSquaresySf08elementsE0_Sf07squaresE0txAA0A6BufferRzSf7ElementRtzlFZ"
  },
  "title" : "sumAndSumOfSquares(_:)"
}
-->

# sumAndSumOfSquares(_:)

Returns the single-precision vector sum and sum of squares.

```
static func sumAndSumOfSquares<U>(_ vector: U) -> (elementsSum: Float, squaresSum: Float) where U : AccelerateBuffer, U.Element == Float
```

## Parameters

`vector`

The vector to sum.

## Discussion

This function calculates and returns the sum and the sum of the squares of the elements of a supplied vector.

The following is an example of using [`sumAndSumOfSquares(_:)`](/documentation/Accelerate/vDSP/sumAndSumOfSquares(_:)-9uec5):

```swift
let a: [Float] = [-1.5, 2.25, 3.6,
                  0.2, -0.1, -4.3]

let sumAndSumOfSquares = vDSP.sumAndSumOfSquares(a)

// Prints "sum 0.1500 sum of squares 38.8125"
print(String(format: "sum %.4f", sumAndSumOfSquares.elementsSum),
      String(format: "sum of squares %.4f", sumAndSumOfSquares.squaresSum))
```

---

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)