<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Numeric",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sj"
  },
  "title" : "Numeric"
}
-->

# Numeric

A type with values that support multiplication.

```
protocol Numeric : AdditiveArithmetic, ExpressibleByIntegerLiteral
```

## Overview

The `Numeric` protocol provides a suitable basis for arithmetic on
scalar values, such as integers and floating-point numbers. You can write
generic methods that operate on any numeric type in the standard library
by using the `Numeric` protocol as a generic constraint.

The following example extends `Sequence` with a method that returns an
array with the sequence’s values multiplied by two.

```
extension Sequence where Element: Numeric {
    func doublingAll() -> [Element] {
        return map { $0 * 2 }
    }
}
```

With this extension, any sequence with elements that conform to `Numeric`
has the `doublingAll()` method. For example, you can double the elements of
an array of doubles or a range of integers:

```
let observations = [1.5, 2.0, 3.25, 4.875, 5.5]
let doubledObservations = observations.doublingAll()
// doubledObservations == [3.0, 4.0, 6.5, 9.75, 11.0]

let integers = 0..<8
let doubledIntegers = integers.doublingAll()
// doubledIntegers == [0, 2, 4, 6, 8, 10, 12, 14]
```

# Conforming to the Numeric Protocol

To add `Numeric` protocol conformance to your own custom type, implement
the required initializer and operators, and provide a `magnitude` property
using a type that can represent the magnitude of any value of your custom
type.

## Relationships

### Inherited By

[`UnsignedInteger`](/documentation/Swift/UnsignedInteger)

[`SignedInteger`](/documentation/Swift/SignedInteger)

[`SignedNumeric`](/documentation/Swift/SignedNumeric)

[`BinaryInteger`](/documentation/Swift/BinaryInteger)

[`BinaryFloatingPoint`](/documentation/Swift/BinaryFloatingPoint)

[`FloatingPoint`](/documentation/Swift/FloatingPoint)

[`FixedWidthInteger`](/documentation/Swift/FixedWidthInteger)

### Inherits From

[`ExpressibleByIntegerLiteral`](/documentation/Swift/ExpressibleByIntegerLiteral)

[`AdditiveArithmetic`](/documentation/Swift/AdditiveArithmetic)

[`Equatable`](/documentation/Swift/Equatable)

### Conforming Types

[`Int128`](/documentation/Swift/Int128)

[`Int8`](/documentation/Swift/Int8)

[`Int32`](/documentation/Swift/Int32)

[`UInt64`](/documentation/Swift/UInt64)

[`Int`](/documentation/Swift/Int)

[`Int64`](/documentation/Swift/Int64)

[`UInt`](/documentation/Swift/UInt)

[`Int16`](/documentation/Swift/Int16)

[`Float80`](/documentation/Swift/Float80)

[`Float16`](/documentation/Swift/Float16)

[`UInt128`](/documentation/Swift/UInt128)

[`UInt32`](/documentation/Swift/UInt32)

[`Float`](/documentation/Swift/Float)

[`UInt16`](/documentation/Swift/UInt16)

[`Double`](/documentation/Swift/Double)

[`UInt8`](/documentation/Swift/UInt8)

---

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)