Skip to content

FloatMul

Description

Generic multiplication convenience macro for Float.

Parameters

Name Direction Description
result out Destination for the product
a in Left operand
b in Right operand selected through generic dispatch

Usage example (from documentation)

  FloatMul(&product, &value, 0.5f);

Success

Returns true; *result holds a * b with the exponents summed and the significand normalized.

Failure

Returns false if an intermediate allocation (significand multiply / normalize) fails; *result is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    bool test_float_mul_small_small(void) {
        WriteFmt("Testing FloatMul with small floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_mul_very_large_small(void) {
        WriteFmt("Testing FloatMul with very large and small floats\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        text = FloatToStr(&result_value);
    
    bool test_float_mul_generic(void) {
        WriteFmt("Testing FloatMul generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        text        = FloatToStr(&result_value);
        bool result = ZstrCompare(StrBegin(&text), "3") == 0;
    
        StrDeinit(&text);
        FloatMul(&result_value, &a, &whole);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3") == 0);
    
        StrDeinit(&text);
        FloatMul(&result_value, &a, 2u);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "3") == 0);
    
        StrDeinit(&text);
        FloatMul(&result_value, &a, -2);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "-3") == 0);
    
        StrDeinit(&text);
        FloatMul(&result_value, &a, 0.5f);
        text   = FloatToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "0.75") == 0);
Last updated on