greatest common divisor implementation

Matthias Walter xammy at xammy.homelinux.net
Mon Feb 7 12:18:33 PST 2011


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


More information about the Digitalmars-d mailing list