Rational numbers in D

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Sun Jun 10 11:53:25 PDT 2012


On Sunday, 10 June 2012 at 14:34:17 UTC, Joseph Rushton Wakeling 
wrote:
> On 10/06/12 13:17, Joseph Rushton Wakeling wrote:
>> I saw that Bearophile has contributed some code for this:
>> http://d.puremagic.com/issues/show_bug.cgi?id=7102#c3
>
> Ooops, not code, just a spec.  If people are interested I'll 
> see if I can write something based on this.

This is not quite ready for prime time, but I have implemented a 
fixed-size integer module which includes a gcd algorithm. It 
limited to unsigned integers at the moment:

https://github.com/andersonpd/decimal/blob/master/decimal/unsigned.d

The gcd algorithm is base on Algorithm 1.18, BinaryGcd, p. 31, 
from Modern Computer Arithmetic, Richard Brent and Paul 
Zimmermann, Cambridge University Press, 2010.

An online PDF version is found at 
http://www.loria.fr/~zimmerma/mca/pub226.html

I don't know that it is particularly efficient but with small 
integers (< 1000 bits) it should be competitive.

Paul


More information about the Digitalmars-d mailing list