IntModAdd
Description
Compute (a + b) mod modulus.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the reduced sum |
a |
in | Left operand |
b |
in | Right operand |
modulus |
in | Modulus |
Usage example (from documentation)
IntModAdd(&result, &a, &b, &modulus);Success
Returns true. *result holds (a + b) mod modulus.
Failure
Returns false on modulus == 0 or allocator OOM. *result is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:2316:
}
bool IntModAdd(Int *result, const Int *a, const Int *b, const Int *modulus) {
ValidateInt(result);
ValidateInt(a);- In
Math.c:683:
bool test_int_mod_add(void) {
WriteFmt("Testing IntModAdd\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:692:
Int result_value = IntInit(&alloc.base);
IntModAdd(&result_value, &a, &b, &m);
bool result = IntToU64(&result_value) == 12;- In
Math.c:1704:
// and IntIsZero re-validates modulus, all aborting identically.)
bool test_m13_modadd_null_result(void) {
WriteFmt("Testing IntModAdd NULL result handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1712:
Int m = IntFrom(11, &alloc.base);
IntModAdd(NULL, &a, &b, &m);
IntDeinit(&a);- In
Math.c:4159:
Int r = IntFrom(7u, a);
bool ok = IntModAdd(&r, &x, &y, &m); // frees ar/br/sum on success (2042-2044)
ok = ok && IntToU64(&r) == (12345u % 1009u + 67890u % 1009u) % 1009u;
Last updated on