Skip to content

IntDiv

Description

Generic division convenience macro.

Parameters

Name Direction Description
result out Destination for the quotient
dividend in Dividend
divisor in Divisor selected through generic dispatch

Usage example (from documentation)

  IntDiv(&quotient, &value, 10u);

Success

Returns true; *result holds the floor quotient of dividend / divisor.

Failure

Returns false when divisor is zero (logged) or when an intermediate allocation fails; *result is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    bool test_int_div(void) {
        WriteFmt("Testing IntDiv generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int result_value = IntInit(&alloc.base);
    
        IntDiv(&result_value, &dividend, 10u);
    
        bool result = IntToU64(&result_value) == 12;
    
    bool test_int_div_scalar_zero_divisor(void) {
        WriteFmt("Testing IntDiv scalar zero-divisor handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int quotient = IntFrom(99, &alloc.base);
    
        IntDiv(&quotient, &dividend, 0u);
        bool result = IntCompare(&quotient, 99) == 0;
Last updated on