FloatAdd
Description
Generic addition convenience macro for Float.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the sum |
a |
in | Left operand |
b |
in | Right operand selected through generic dispatch |
Usage example (from documentation)
FloatAdd(&sum, &value, 1.25);Success
Returns true; *result holds a + b with shared exponent and normalized significand.
Failure
Returns false if an intermediate allocation (clone / rescale / add) fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Type.c:355:
Str t = StrInit(&alloc.base);
FloatAdd(&r, &a, &b);
t = FloatToStr(&r);
bool ok = ZstrCompare(StrBegin(&t), "100.1") == 0;- In
Type.c:377:
Str t = StrInit(&alloc.base);
FloatAdd(&r, &a, &z);
t = FloatToStr(&r);
bool ok = ZstrCompare(StrBegin(&t), "12.5") == 0;- In
Math.c:96:
bool test_float_add_small_small(void) {
WriteFmt("Testing FloatAdd with small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:105:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Math.c:119:
bool test_float_add_very_large_large(void) {
WriteFmt("Testing FloatAdd with very large floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:128:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Math.c:142:
bool test_float_add_generic(void) {
WriteFmt("Testing FloatAdd generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:152:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);
bool result = ZstrCompare(StrBegin(&text), "2") == 0;- In
Math.c:157:
StrDeinit(&text);
FloatAdd(&result_value, &a, &whole);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "3.25") == 0);- In
Math.c:162:
StrDeinit(&text);
FloatAdd(&result_value, &a, 2u);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "3.25") == 0);- In
Math.c:167:
StrDeinit(&text);
FloatAdd(&result_value, &a, -1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "0.25") == 0);- In
Math.c:172:
StrDeinit(&text);
FloatAdd(&result_value, &a, 0.75f);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2") == 0);- In
Math.c:177:
StrDeinit(&text);
FloatAdd(&result_value, &a, 0.75);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2") == 0);- In
Math.c:492:
// Real: -2 + 5 = 3. Mutant: -3.
bool test_m1_add_neg_lhs_larger_pos_rhs(void) {
WriteFmt("Testing FloatAdd sign: -2 + 5 = 3\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:501:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Math.c:520:
// the mutant; kept for behavioral coverage of the cmp<0 branch.
bool test_m1_add_pos_lhs_larger_neg_rhs(void) {
WriteFmt("Testing FloatAdd sign: 2 + (-5) = -3\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:529:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Math.c:546:
// yield -0.75.
bool test_m1_add_sign_from_larger_magnitude(void) {
WriteFmt("Testing FloatAdd sign w/ fractions: -0.25 + 1 = 0.75\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:555:
Str text = StrInit(&alloc.base);
FloatAdd(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Math.c:998:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, &b);
FloatDeinit(&a);- In
Math.c:1023:
Float r = FloatFromStr("123456789", &dbg.base); // pre-populated dest
bool ok = FloatAdd(&r, &a, &b);
FloatDeinit(&a);- In
Math.c:1046:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, &b);
ok = ok && FloatIsZero(&r);- In
Math.c:1141:
Int b = IntFrom(2, &dbg.base);
bool ok = FloatAdd(&r, &a, &b);
FloatDeinit(&a);- In
Math.c:1157:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, 2u);
FloatDeinit(&a);- In
Math.c:1172:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, -2);
FloatDeinit(&a);- In
Math.c:1187:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, 0.5f);
FloatDeinit(&a);- In
Math.c:1202:
Float r = FloatInit(&dbg.base);
bool ok = FloatAdd(&r, &a, 0.25);
FloatDeinit(&a);
Last updated on