<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "P256K",
  "identifier" : "/documentation/P256K/UInt256/addMod(_:modulus:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "P256K"
    ],
    "preciseIdentifier" : "s:5P256K7UInt256V6addMod_7modulusA2C_ACtF"
  },
  "title" : "addMod(_:modulus:)"
}
-->

# addMod(_:modulus:)

Returns `(self + other) % modulus`.

```
func addMod(_ other: UInt256, modulus: UInt256) -> UInt256
```

## Parameters

`other`

The value to add.

`modulus`

The modulus (must be ≥ 2).

## Return Value

`(self + other) mod modulus`.

## Discussion

Uses `addingReportingOverflow` to detect the 257-bit intermediate, then reduces
modulo `modulus` via `dividingFullWidth` when overflow occurs or via a simple
compare-and-subtract when it doesn’t.

> Precondition: `modulus >= 2`.