Instance Method
mulMod(_:modulus:)
Returns (self * other) % modulus.
- iOS 18.0+
- macCatalyst 18.0+
- macOS 15.0+
- tvOS 18.0+
- visionOS 2.0+
- watchOS 11.0+
func mulMod(_ other: UInt256, modulus: UInt256) -> UInt256
Parameters
-
other
-
The value to multiply.
-
modulus
-
The modulus (must be non-zero).
Return Value
(self * other) mod modulus.
Discussion
Computes the full 512-bit intermediate via multipliedFullWidth(by:) and reduces with a single dividingFullWidth call. Assumes both operands are already reduced modulo modulus (self < modulus and other < modulus) so the intermediate does not overflow the 512-bit (high, low) tuple when modulus is near 2^256.
Precondition
modulus != 0, self < modulus, other < modulus.