[phobos] Rational for review

David Simcha dsimcha at gmail.com
Fri Aug 27 17:48:37 PDT 2010


  I've cleaned up/fixed the bit rot in my Rational library.  It's 
available for review at:  
http://dsource.org/projects/scrapple/browser/trunk/rational/rational.d?rev=785 
.

Known issues:

1.  Due to bugs in BigInt (mainly 4742 
http://d.puremagic.com/issues/show_bug.cgi?id=4742), BigInt 
instantiations don't play nicely with builtin integer instantiations.  
For example, this doesn't work:

auto a = rational(BigInt(1), 2) * rational(8, 7);

2.  I couldn't figure out how to handle the case of user-defined 
fixed-width integer types in the decimal conversion (opCast) function, 
so it just assumes non-builtin integer types are arbitrary precision.  
The biggest problem is lack of a way of introspecting whether the 
integer is fixed or arbitrary width and what its fixed width might be if 
it is, in fact, fixed.  The secondary problem is that I don't know of a 
good algorithm (though I'm sure I could find one if I tried) for 
converting fixed-width integers to floating point numbers in software.  
Arbitrary precision is much easier.

3.  There is a small amount of special case ad-hockery to make things 
work with std.bigint.BigInt.  I consider these bug workarounds.  In 
principle, everything should work with any user defined arbitrary 
precision integer if it overloads everything it's supposed to overload.


More information about the phobos mailing list