IntAdd
Description
Generic addition convenience macro. Dispatches on the type of b to the matching IntAdd* overload.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the sum |
a |
in | Left operand |
b |
in | Right operand (Int, pointer, u64, or i64 compatible type) |
Usage example (from documentation)
IntAdd(&sum, &value, 10u);Success
Returns true; *result holds a + b.
Failure
Returns false if an intermediate allocation fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Type.c:115:
// Real code yields 256 with bit length 9; the mutant diverges on both checks.
bool test_m27_normalize_trims_via_add(void) {
WriteFmt("Testing int_normalize resize length via IntAdd(255,1)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Type.c:123:
Int sum = IntInit(&alloc.base);
IntAdd(&sum, &a, &b);
bool result = (IntToU64(&sum) == 256);- In
Math.c:107:
bool test_int_add(void) {
WriteFmt("Testing IntAdd\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:116:
Str text = StrInit(&alloc.base);
IntAdd(&result_value, &a, &b);
text = IntToBinary(&result_value);- In
Math.c:131:
bool test_int_add_generic(void) {
WriteFmt("Testing IntAdd generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:141:
Str text = StrInit(&alloc.base);
IntAdd(&result_value, &base, &rhs);
bool result = IntToU64(&result_value) == 42;- In
Math.c:144:
bool result = IntToU64(&result_value) == 42;
IntAdd(&result_value, &base, 2);
result = result && (IntToU64(&result_value) == 42);- In
Math.c:147:
result = result && (IntToU64(&result_value) == 42);
IntAdd(&result_value, &base, -2);
result = result && (IntToU64(&result_value) == 38);- In
Math.c:150:
result = result && (IntToU64(&result_value) == 38);
IntAdd(&result_value, &huge, 10);
text = IntToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "123456789012345678901234567900") == 0);- In
Math.c:960:
bool test_int_add_null_result(void) {
WriteFmt("Testing IntAdd NULL result handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:967:
Int b = IntFrom(2, &alloc.base);
IntAdd(NULL, &a, &b);
DefaultAllocatorDeinit(&alloc);
return false;- In
Math.c:1929:
Int sum = IntInit(&alloc.base);
IntAdd(&sum, &ones, &one);
Str bits = IntToBinary(&sum);- In
Math.c:3726:
Int r = IntFrom(7u, a);
bool ok = IntAdd(&r, &x, &y);
ok = ok && IntToU64(&r) == 0xFFFFFFFFull + 0xFFFFFFFFull;- In
Math.c:3765:
Int r = IntFrom(7u, a);
bool ok = IntAdd(&r, &x, 250u);
ok = ok && IntToU64(&r) == 750u;
Last updated on