FloatDiv
Description
Generic division convenience macro for Float.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the quotient |
a |
in | Dividend |
b |
in | Divisor selected through generic dispatch |
precision |
in | Decimal precision to retain |
Usage example (from documentation)
FloatDiv("ient, &value, 3.0, 8);Success
Returns true; *result holds a / b with precision decimal digits retained. When a is zero *result is set to zero without further work.
Failure
Returns false when b is zero (logged) or when any intermediate allocation (scale / multiply / divide) fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Math.c:371:
bool test_float_div_small_small(void) {
WriteFmt("Testing FloatDiv with small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:380:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 3);
text = FloatToStr(&result_value);- In
Math.c:394:
bool test_float_div_very_large_small(void) {
WriteFmt("Testing FloatDiv with very large and small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:403:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 0);
text = FloatToStr(&result_value);- In
Math.c:417:
bool test_float_div_generic(void) {
WriteFmt("Testing FloatDiv generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:427:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 1);
text = FloatToStr(&result_value);
bool result = ZstrCompare(StrBegin(&text), "3") == 0;- In
Math.c:432:
StrDeinit(&text);
FloatDiv(&result_value, &a, &whole, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2.5") == 0);- In
Math.c:437:
StrDeinit(&text);
FloatDiv(&result_value, &a, 3u, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2.5") == 0);- In
Math.c:442:
StrDeinit(&text);
FloatDiv(&result_value, &a, -3, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "-2.5") == 0);- In
Math.c:447:
StrDeinit(&text);
FloatDiv(&result_value, &a, 0.5f, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "15") == 0);- In
Math.c:452:
StrDeinit(&text);
FloatDiv(&result_value, &a, 0.5, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "15") == 0);- In
Math.c:466:
bool test_float_div_by_zero(void) {
WriteFmt("Testing FloatDiv divide-by-zero handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:475:
bool ok;
ok = !FloatDiv(&r, &a, &b, 4);
ok = ok && FloatIsZero(&r);- In
Math.c:618:
// exponent; the lt_to_le mutant aborts -> killed.
static bool test_m10_div_exp_min_boundary(void) {
WriteFmt("Testing exponent-diff at INT64_MIN boundary (FloatDiv)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:626:
Float r = FloatInit(&alloc.base);
bool ok = FloatDiv(&r, &a, &b, 0);
ok = ok && (FloatExponent(&r) == INT64_MIN);- In
Math.c:640:
// boundary exponent; the gt_to_ge mutant aborts -> killed.
static bool test_m10_div_exp_max_boundary(void) {
WriteFmt("Testing exponent-diff at INT64_MAX boundary (FloatDiv)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:648:
Float r = FloatInit(&alloc.base);
bool ok = FloatDiv(&r, &a, &b, 0);
ok = ok && (FloatExponent(&r) == INT64_MAX);- In
Math.c:670:
Float r = FloatInit(&alloc.base);
bool ok = !FloatDiv(&r, &a, 0.0, 4);
FloatDeinit(&a);- In
Math.c:794:
bool test_m12_div_int_by_zero_returns_false(void) {
WriteFmt("Testing FloatDiv(Int 0) returns false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:803:
// Real float_div rejects division by zero -> false.
bool ok = FloatDiv(&result, &a, &zero, 4);
bool pass = (ok == false);- In
Math.c:815:
bool test_m12_div_i64_by_zero_returns_false(void) {
WriteFmt("Testing FloatDiv(i64 0) returns false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:822:
Float result = FloatInit(&alloc.base);
bool ok = FloatDiv(&result, &a, (signed long long)0, 4);
bool pass = (ok == false);- In
Math.c:833:
bool test_m12_div_f32_by_zero_returns_false(void) {
WriteFmt("Testing FloatDiv(f32 0) returns false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:840:
Float result = FloatInit(&alloc.base);
bool ok = FloatDiv(&result, &a, 0.0f, 4);
bool pass = (ok == false);- In
Math.c:904:
Str text = StrInit(&alloc.base);
bool ok = FloatDiv("ient, &a, &b, 8);
text = FloatToStr("ient);
bool result = ok && (ZstrCompare(StrBegin(&text), "2") == 0);- In
Math.c:923:
///
bool test_m9_div_u64_by_zero_returns_false(void) {
WriteFmt("Testing FloatDiv(u64) divide-by-zero returns false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:930:
Float r = FloatInit(&alloc.base);
bool ok = (FloatDiv(&r, &a, 0u, 4) == false);
FloatDeinit(&a);- In
Math.c:944:
///
bool test_m9_div_u64_by_zero_leaves_result_unchanged(void) {
WriteFmt("Testing FloatDiv(u64) divide-by-zero keeps result zero\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:951:
Float r = FloatInit(&alloc.base);
bool ok = !FloatDiv(&r, &a, 0u, 4);
ok = ok && FloatIsZero(&r);- In
Math.c:965:
///
bool test_m9_div_u64_exact(void) {
WriteFmt("Testing FloatDiv(u64) exact quotient\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:973:
Str text;
bool ok = FloatDiv(&r, &a, 3u, 1);
text = FloatToStr(&r);
ok = ok && (ZstrCompare(StrBegin(&text), "2.5") == 0);- In
Math.c:1072:
Float r = FloatFromStr("987654321", &dbg.base); // pre-populated dest
bool ok = FloatDiv(&r, &a, &b, 8u);
FloatDeinit(&a);- In
Math.c:1094:
Float r = FloatFromStr("55555", &dbg.base); // pre-populated dest
bool ok = FloatDiv(&r, &a, &b, 4u);
ok = ok && FloatIsZero(&r);- In
Math.c:1389:
Int b = IntFrom(4, &dbg.base);
bool ok = FloatDiv(&r, &a, &b, 6u);
FloatDeinit(&a);- In
Math.c:1405:
Float r = FloatInit(&dbg.base);
bool ok = FloatDiv(&r, &a, 4u, 6u);
FloatDeinit(&a);- In
Math.c:1420:
Float r = FloatInit(&dbg.base);
bool ok = FloatDiv(&r, &a, -4, 6u);
FloatDeinit(&a);- In
Math.c:1435:
Float r = FloatInit(&dbg.base);
bool ok = FloatDiv(&r, &a, 4.0f, 6u);
FloatDeinit(&a);- In
Math.c:1450:
Float r = FloatInit(&dbg.base);
bool ok = FloatDiv(&r, &a, 4.0, 6u);
FloatDeinit(&a);
Last updated on