Re_: Calling hot shot coders!
From: Aldo (gasparuga_at_yahoo.ca)
Date: 12/29/04
- Next message: gaspar: "Re: Calling hot shot coders!"
- Previous message: Bill Unruh: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 28 Dec 2004 19:56:07 -0800
In reply to the post (12-12-2004) of Bob Silverman:
> Are you a hot shot coder?
It doesn't matter.
Bob, shouldn't part of your code look like this:
if (rem >= divisor)
{
q = 5;
rem -= divisor;
if (rem >= divisor)
{
q = dividend/divisor;
rem = dividend - q*divisor;
}
}
Or did I miss some magic that your placement of curly brackets does?
I deduced that your code implements the well known extended gcd algorithm,
with some divisions replaced by subtractions. However it is slower than
this straight form obtained by cutting down your code:
single_modinv(a,modulus)
int a,modulus;
{ /* start of single_modinv */
register int ps,ps1,ps2=1,parity,dividend,divisor,rem,q;
q = modulus/a;
rem = modulus - a*q;
dividend = a;
divisor = rem;
ps1 = q;
parity = 0;
while (rem != 0)
{
q = dividend/divisor;
rem = dividend - q*divisor;
ps = q*ps1 + ps2;
ps2 = ps1;
ps1 = ps;
dividend = divisor;
divisor = rem;
parity = 1 - parity;
}
if (parity == 0) return(ps2);
else return(modulus-ps2);
} /* end of single_modinv */
Of course, it depends on the implementation of the division operation.
My testing and comparisons were done with QuickC compiler.
Respectfully,
Aldo D.
- Next message: gaspar: "Re: Calling hot shot coders!"
- Previous message: Bill Unruh: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|