Skip to content

IntDivExact

Description

Generic exact-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)

  bool ok = IntDivExact(&quotient, &value, 5u);

Success

Returns true when the division is exact.

Failure

Returns false otherwise.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    bool test_int_div_exact(void) {
        WriteFmt("Testing IntDivExact generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str text         = StrInit(&alloc.base);
    
        bool result = IntDivExact(&result_value, &dividend, 90u);
        text        = IntToStr(&result_value);
        result      = result && (ZstrCompare(StrBegin(&text), "137174210013717421") == 0);
    
    bool test_int_div_exact_failure_preserves_result(void) {
        WriteFmt("Testing IntDivExact failure handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int result_value = IntFrom(99, &alloc.base);
    
        bool result = !IntDivExact(&result_value, &dividend, &divisor);
        result      = result && (IntToU64(&result_value) == 99);
Last updated on