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
Float.Math.c:325:
bool test_float_div_small_small(void) {
WriteFmt("Testing FloatDiv with small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:334:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 3);
text = FloatToStr(&result_value);- In
Float.Math.c:348:
bool test_float_div_very_large_small(void) {
WriteFmt("Testing FloatDiv with very large and small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:357:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 0);
text = FloatToStr(&result_value);- In
Float.Math.c:371:
bool test_float_div_generic(void) {
WriteFmt("Testing FloatDiv generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:381:
Str text = StrInit(&alloc.base);
FloatDiv(&result_value, &a, &b, 1);
text = FloatToStr(&result_value);
bool result = ZstrCompare(StrBegin(&text), "3") == 0;- In
Float.Math.c:386:
StrDeinit(&text);
FloatDiv(&result_value, &a, &whole, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2.5") == 0);- In
Float.Math.c:391:
StrDeinit(&text);
FloatDiv(&result_value, &a, 3u, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "2.5") == 0);- In
Float.Math.c:396:
StrDeinit(&text);
FloatDiv(&result_value, &a, -3, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "-2.5") == 0);- In
Float.Math.c:401:
StrDeinit(&text);
FloatDiv(&result_value, &a, 0.5f, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "15") == 0);- In
Float.Math.c:406:
StrDeinit(&text);
FloatDiv(&result_value, &a, 0.5, 1);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "15") == 0);- In
Float.Math.c:420:
bool test_float_div_by_zero(void) {
WriteFmt("Testing FloatDiv divide-by-zero handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:429:
bool ok;
ok = !FloatDiv(&r, &a, &b, 4);
ok = ok && FloatIsZero(&r);
Last updated on