Skip to content

IntPow

Description

Generic exponentiation convenience macro.

Parameters

Name Direction Description
result out Destination for the result
base in Base value
exponent in Exponent selected through generic dispatch

Usage example (from documentation)

  IntPow(&power, &base, 20u);

Success

Returns true; *result holds base ** exponent computed via repeated-squaring.

Failure

Returns false if an intermediate allocation fails or if exponent is negative; *result is unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
            Int pow5 = IntInit(alloc);
            Int sig  = IntInit(alloc);
            if (!int_try_from_u64(&five, 5u, alloc) || !IntPow(&pow5, &five, n) ||
                !int_mul(&sig, &out->significand, &pow5)) {
                IntDeinit(&five);
    
    bool test_int_pow_generic(void) {
        WriteFmt("Testing IntPow generic dispatch\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str text         = StrInit(&alloc.base);
    
        IntPow(&result_value, &base, 20u);
        text        = IntToStr(&result_value);
        bool result = ZstrCompare(StrBegin(&text), "79792266297612001") == 0;
    
        StrDeinit(&text);
        IntPow(&result_value, &base, &exponent);
        text   = IntToStr(&result_value);
        result = result && (ZstrCompare(StrBegin(&text), "79792266297612001") == 0);
Last updated on