Instance Method
addMod(_:modulus:)
Returns (self + other) % modulus.
- iOS 18.0+
- macCatalyst 18.0+
- macOS 15.0+
- tvOS 18.0+
- visionOS 2.0+
- watchOS 11.0+
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.