Skip to content

IntModDiv

Description

Compute modular division a / b (mod modulus).

Parameters

Name Direction Description
result out Destination for the reduced quotient
a in Numerator
b in Denominator
modulus in Modulus

Usage example (from documentation)

  bool ok = IntModDiv(&result, &a, &b, &modulus);

Success

Returns true when a modular inverse for b exists.

Failure

Returns false otherwise.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntModDiv(Int *result, const Int *a, const Int *b, const Int *modulus) {
        ValidateInt(result);
        ValidateInt(a);
    
    bool test_int_mod_div(void) {
        WriteFmt("Testing IntModDiv\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int check        = IntInit(&alloc.base);
    
        bool result = IntModDiv(&result_value, &a, &b, &m);
        result      = result && (IntToU64(&result_value) == 12);
    
    bool test_int_mod_div_no_solution(void) {
        WriteFmt("Testing IntModDiv no-solution case\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int result_value = IntFrom(99, &alloc.base);
    
        bool result = !IntModDiv(&result_value, &a, &b, &m);
        result      = result && (IntCompare(&result_value, 99) == 0);
    
    bool test_int_mod_div_zero_modulus(void) {
        WriteFmt("Testing IntModDiv zero modulus handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int result_value = IntFrom(99, &alloc.base);
    
        bool result = !IntModDiv(&result_value, &a, &b, &m);
        result      = result && (IntCompare(&result_value, 99) == 0);
Last updated on