Anything in the review queue?

dsimcha dsimcha at yahoo.com
Sun Mar 20 19:34:26 PDT 2011


On 3/20/2011 10:26 PM, bearophile wrote:
> dsimcha:
>
>> On second thought, given the difficulty finding anything else, rational
>> may be the thing that's most ready.  I'll offer it up for review now
>
> It's good to have rationals in Phobos, thank you.
>
> Is this GCD? There is already a gcd in Phobos. Is this efficient when numbers gets very large?
> CommonInteger!(I1,I2) gcf(I1, I2)(I1 num1, I2 num2);
>

I knew someone was going to ask this, so I probably should have answered 
it pre-emptively.  std.numeric.gcd doesn't work with BigInts.  I'm 
considering making my implementation private and eventually fixing 
std.numeric rather than having duplicate public functionality.

>
> An alternative is to give the number of binary digits of precision for the mantissa (see std.math.feqrel):
> Rational!(Int) toRational(Int)(real floatNum, real epsilon = 1e-08);

That's worth considering.  The only reason I did it the way I did is 
because the Maxima computer algebra system did it this way and, when in 
doubt, I generally do what Maxima does in this library.  I also think 
absolute error is the better metric for this case.  If you do:

auto foo = toRational!BigInt(1e-200);

Do we really want to return some ridiculously huge number (that possibly 
overflows in the case of fixed width integers) for the denominator in 
this case?


More information about the Digitalmars-d mailing list