FloatSub
Description
Generic subtraction convenience macro for Float.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the difference |
a |
in | Left operand |
b |
in | Right operand selected through generic dispatch |
Usage example (from documentation)
FloatSub(&diff, &value, 2u);Success
Returns true; *result holds a - b with shared exponent and normalized significand.
Failure
Returns false if an intermediate allocation (clone / rescale / subtract) fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Float.Math.c:145:
bool test_float_sub_small_small(void) {
WriteFmt("Testing FloatSub with small floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:154:
Str text = StrInit(&alloc.base);
FloatSub(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Float.Math.c:168:
bool test_float_sub_very_large_large(void) {
WriteFmt("Testing FloatSub with very large floats\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:177:
Str text = StrInit(&alloc.base);
FloatSub(&result_value, &a, &b);
text = FloatToStr(&result_value);- In
Float.Math.c:191:
bool test_float_sub_generic(void) {
WriteFmt("Testing FloatSub generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Float.Math.c:201:
Str text = StrInit(&alloc.base);
FloatSub(&result_value, &a, &b);
text = FloatToStr(&result_value);
bool result = ZstrCompare(StrBegin(&text), "5") == 0;- In
Float.Math.c:206:
StrDeinit(&text);
FloatSub(&result_value, &a, &whole);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "3.5") == 0);- In
Float.Math.c:211:
StrDeinit(&text);
FloatSub(&result_value, &a, 2u);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "3.5") == 0);- In
Float.Math.c:216:
StrDeinit(&text);
FloatSub(&result_value, &a, -2);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "7.5") == 0);- In
Float.Math.c:221:
StrDeinit(&text);
FloatSub(&result_value, &a, 0.5f);
text = FloatToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "5") == 0);
Last updated on