greatest common divisor implementation

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 7 16:13:57 PST 2011


On 2/7/11 3:18 PM, Matthias Walter wrote:
> Hi everyone,
>
> as I'm currently working on a C++ project which involves gcd
> computations I had a quick look at phobos' implementation.
>
> 1. First thing I saw is that gcd(-3,6) raises an exception, although
> mathematically it is just 2. Of course checking the sign of the
> arguments takes computation time, but for my stuff I'd definitely need
> it. If it's really too expensive then there should be at least another
> routine.
>
> 2. I'd be happy to implement the Extended Euclidean algorithm for phobos
> which also gives multipliers s and t such that gcd(x,y) = s*x + t*y.
>
> Any comments before I start working on it?
>
> Matthias

Please do. I implemented gcd in a hurry because I needed it for unsigned 
numbers, so it's not the greatest it could be. A github pull request 
would be much appreciated!

Andrei


More information about the Digitalmars-d mailing list