Skip to content

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)
    
    bool test_float_sub_small_small(void) {
        WriteFmt("Testing FloatSub with small floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_sub_very_large_large(void) {
        WriteFmt("Testing FloatSub with very large floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_sub_generic(void) {
        WriteFmt("Testing FloatSub generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        text        = FloatToStr(&result_value);
        bool result = ZstrCompare(StrBegin(&text), "5") == 0;
    
        StrDeinit(&text);
        FloatSub(&result_value, &a, &whole);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3.5") == 0);
    
        StrDeinit(&text);
        FloatSub(&result_value, &a, 2u);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3.5") == 0);
    
        StrDeinit(&text);
        FloatSub(&result_value, &a, -2);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "7.5") == 0);
    
        StrDeinit(&text);
        FloatSub(&result_value, &a, 0.5f);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "5") == 0);
Last updated on