IntMul
Description
Generic multiplication convenience macro.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the product |
a |
in | Left operand |
b |
in | Right operand selected through generic dispatch |
Usage example (from documentation)
IntMul(&product, &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
Math.c:240:
bool test_int_mul(void) {
WriteFmt("Testing IntMul\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:248:
Int result_value = IntInit(&alloc.base);
IntMul(&result_value, &a, &b);
bool result = IntToU64(&result_value) == 126;- In
Math.c:260:
bool test_int_mul_scalar(void) {
WriteFmt("Testing IntMul generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:268:
Str text = StrInit(&alloc.base);
IntMul(&result_value, &value, 25u);
text = IntToStr(&result_value);- In
Math.c:281:
bool test_int_mul_zero(void) {
WriteFmt("Testing IntMul with zero\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:289:
Int result_value = IntInit(&alloc.base);
IntMul(&result_value, &a, &b);
bool result = IntIsZero(&result_value);- In
Math.c:1541:
Int product = IntInit(&alloc.base);
bool ok = IntMul(&product, &a, &b);
bool result = ok && (IntToU64(&product) == (u64)121932631112635269ull);- In
Math.c:1566:
Int product = IntInit(&alloc.base);
bool ok = IntMul(&product, &a, &zero);
bool result = ok && IntIsZero(&product);- In
Math.c:1593:
Int b = IntFrom((u64)3u, &alloc.base);
IntMul(NULL, &a, &b);
DefaultAllocatorDeinit(&alloc);- In
Math.c:2302:
/* Signed literal forces int_mul_i64 dispatch. */
bool ok = IntMul(&result_value, &value, (i64)13);
bool result = ok && (IntToU64(&result_value) == 91);- In
Math.c:2326:
Int result_value = IntFrom(99, &alloc.base);
bool ok = IntMul(&result_value, &value, (i64)0);
bool result = ok && (IntToU64(&result_value) == 0);- In
Math.c:3688:
Int r = IntInit(a);
bool ok = IntMul(&r, &x, &y);
ok = ok && IntToU64(&r) == 123456ull * 7891011ull;- In
Math.c:3707:
Int r = IntFrom(42u, a); // r starts non-empty so the internal deinit matters
bool ok = IntMul(&r, &x, &y);
ok = ok && IntIsZero(&r);- In
Math.c:3784:
Int r = IntFrom(7u, a);
bool ok = IntMul(&r, &x, 13u);
ok = ok && IntToU64(&r) == 6500u;- In
Math.c:4658:
Int r = IntFrom(0xDEADBEEFu, a); // pre-populated: holds a live buffer
bool ok = IntMul(&r, &x, &y);
ok = ok && IntToU64(&r) == 123456ull * 7891011ull;- In
Convert.c:620:
Int product = IntInit(&alloc.base);
bool ok = IntMul(&product, &a, &b);
bool result = ok && (IntToU64(&product) == (u64)273u);
Last updated on