On Tue, Oct 01, 2013 at 08:26:49AM +0200, ilya-stromberg wrote: > On Monday, 30 September 2013 at 18:01:29 UTC, Joseph Rushton > Wakeling wrote: > >On 30/09/13 19:39, Joseph Rushton Wakeling wrote: > >>... although the new gcf will fail if passed immutable/const > >>BigInts. > > > >On this note: http://d.puremagic.com/issues/show_bug.cgi?id=11148 > > > >I had to tweak CommonInteger to handle immutable/const BigInts, > >and I'm not sure whether this was done correctly, although it > >seems to be largely in line with how CommonType works. > > Note that denumerator must be allways positive (> 0). > But numerator can be positive, zero or negative, and can be bigger > than denumerator. > It means that we can use different types for numerator and > denumerator: [...]
This is needlessly complex. We should just use signed types for both numerator and denominator, and handle sign by a canonicalization operation (canonicalization is already needed for reducing the fraction to its lowest terms anyway, and if gcd is implemented appropriately, it will return a number of appropriate sign to cancel out the negative sign in the denominator (or numerator), so this doesn't even need to be a separate check). T -- A computer doesn't mind if its programs are put to purposes that don't match their names. -- D. Knuth
