Preliminary submission - std.rational and std.typelist

Arlen arlen.ng at gmx.com
Mon Oct 8 19:47:28 PDT 2012


On Mon, Oct 8, 2012 at 4:37 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> Arlen:
>
>
>> Yes, std.math.abs and std.numeric.gcd are very easy to implement for
>> BigInt,
>
>
> Don doesn't agree regarding the gcd. To compute the gcd efficiently on large
> numbers you need not easy algorithms.
>
> See:
> http://d.puremagic.com/issues/show_bug.cgi?id=7102
>
> Bye,
> bearophile


gcd() is very easy to implement:

BigInt _gcd(BigInt a, BigInt b)
{
  enforce(a >= 0 && b >=0);
  while (b != 0) {
    auto t = b;
    b = a % b;
    a = t;
  }
  return a;
}

It's not going to be the fastest or the most efficient, but it does
produce correct results, and that's the most important thing when
implementing mathematical functions IMO.  You can always improve the
performance later.  Implementing pow(), on the other hand, is very
difficult and complex.


More information about the Digitalmars-d mailing list