Skip to content

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)
    
    bool test_float_add_small_small(void) {
        WriteFmt("Testing FloatAdd with small floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_add_very_large_large(void) {
        WriteFmt("Testing FloatAdd with very large floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_add_generic(void) {
        WriteFmt("Testing FloatAdd generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        text        = FloatToStr(&result_value);
        bool result = ZstrCompare(StrBegin(&text), "2") == 0;
    
        StrDeinit(&text);
        FloatAdd(&result_value, &a, &whole);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3.25") == 0);
    
        StrDeinit(&text);
        FloatAdd(&result_value, &a, 2u);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3.25") == 0);
    
        StrDeinit(&text);
        FloatAdd(&result_value, &a, -1);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "0.25") == 0);
    
        StrDeinit(&text);
        FloatAdd(&result_value, &a, 0.75f);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "2") == 0);
    
        StrDeinit(&text);
        FloatAdd(&result_value, &a, 0.75);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "2") == 0);
Last updated on