[bigint] bigint Project

Ludo Ruisch <ludo_ruisch at hotmail.com>
Tue Nov 5 18:59:36 PST 2013


Dear Matt,

I really liked your project! Great job. I also saw you where using the pow function in the sample code and i throught i could make it faster.
I made the pow function in BigIntegerAlgorithms.cc and it speeds up a lot! Hopefully you will also add it in your project.

Vriendelijke Groet,

Ludo Ruisch from the Netherlands ^_^

BigUnsigned pow(const BigUnsigned &a, const BigUnsigned &b)
{
    BigUnsigned result = 1;
    BigUnsigned loop_count = 0;
    BigUnsigned multiply_result = a;
    BigUnsigned multiply_count = 1;
    
    step_1:
    multiply_result *= multiply_result;
    multiply_count *= 2;
    
    if(loop_count + (multiply_count * 2) <= b)
    {
        goto step_1;
    }
    else if(loop_count + (multiply_count) <= b)
    {
        result *= multiply_result;
        loop_count += multiply_count;
        multiply_result = a;
        multiply_count = 1;
        
        if(loop_count + (multiply_count * 2) <= b)
            goto step_1;
    }
    result *= multiply_result;
    
    return result;
}
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mattmccutchen.net/mailman/archives/bigint/attachments/20131106/57eab51e/attachment.html>


More information about the bigint mailing list