[Tutor] code for expressing rationals in arbitrarty bases

Brian van den Broek bvande at po-box.mcgill.ca
Sat Jul 2 22:36:15 CEST 2005


Hi all,

In a private exchange about floating point representation error spun 
off of c.l.p., I'd sent someone some code to express rationals 
(subject to some constraints) in arbitrary bases, 1 < base < 37. The 
aim was to illustrate my claim that whether a rational had a repeating 
expansion[*] or not was a function of base of representation.

Well, he went and posted it back to c.l.p. :-(
So, it is out there, even though it isn't so good that I'd have chosen 
to put it in a public space (other than Tutor). It is also long, as it 
includes some tests and sanity checks on the input. *If* anyone has 
the time and interest, I'd appreciate comments:
<http://article.gmane.org/gmane.comp.python.general/409948>. If not, 
no worries. :-)

To my embarrassment, I see that I'd commented out, but not removed, 
debug print statements. etc.

[*] Does anyone know a term for a non-fractional representation of a 
rational in arbitrary base? For particular bases, decimal expansion, 
binary expansion, etc. But is there a term for the general case, other 
than base-n expansion?

Best to all,

Brian vdB



More information about the Tutor mailing list