On 3/21/2011 8:33 PM, Andrei Alexandrescu wrote:
I think by and large failure to define rational for BigInt in a way that
has many commonalities with rational for built-in integrals reflects a
failure of BigInt. By its very design, BigInt is supposed to
transparently replace integers. If this is largely the case, the design
has succeeded. If the design of anything must be reworked essentially
from scratch to work with BigInt instead of int et al, then the
abstraction may be too porous to be useful.

There are a few approaches we can take from here. One is to define
certain traits that differentiate BigInt from other integrals (e.g.
preferAdditionToMultiplication or whatnot), and then design Rational to
use those traits. Another is of course to specialize the entire Rational
on BigInt. Third would be to specialize certain core routines (gcd and
friends) for BigInt and keep Rational agnostic.

Anyhow, BigInt should be cheap to copy (i.e. use refcounting). If there
are good reasons for which that's impossible, we should give up on the
dream of enacting that assumption throughout Phobos. Don?


Andrei

The biggest perf issue, though, seems to be Euler's algorithm instead of BinaryGCD. This is definitely going to get fixed eventually by me, since I've read up on BinaryGCD and it doesn't look hard to implement generically. I naively thought Euler's algorithm was pretty darn efficient when I wrote the first version, not knowing much about how BigInts work under the hood. I'm not sure if Don had something even more efficient than a good generic BinaryGCD implementation in mind, or if there are other areas where a templated Rational is a Bad Idea, though.

Reply via email to