Re: rational to floating point

David Chase <chase@theworld.com>
14 Mar 2003 11:05:55 -0500

          From comp.compilers

Related articles
rational to floating point thant@acm.org (Thant Tessman) (2003-03-09)
Re: rational to floating point chase@theworld.com (David Chase) (2003-03-14)
Re: rational to floating point nmm1@cus.cam.ac.uk (2003-03-14)
Re: rational to floating point thant@acm.org (Thant Tessman) (2003-03-14)
Re: rational to floating point joachim_d@gmx.de (Joachim Durchholz) (2003-03-14)
Re: rational to floating point ajo@andrew.cmu.edu (Arthur J. O'Dwyer) (2003-03-14)
Re: rational to floating point gah@ugcs.caltech.edu (Glen Herrmannsfeldt) (2003-03-14)
Re: rational to floating point tmk@netvision.net.il (2003-03-14)
[2 later articles]
| List of all articles for this month |

From: David Chase <chase@theworld.com>
Newsgroups: comp.compilers
Date: 14 Mar 2003 11:05:55 -0500
Organization: Little or none
References: 03-03-035
Keywords: arithmetic
Posted-Date: 14 Mar 2003 11:05:55 EST

Thant Tessman wrote:


>The question is: Under what conditions will a rational number produce
>an infinite stream of digits for a given base?


You need _The Book of Numbers_, by John H. Conway and Richard K. Guy.
You needed this book anyway, but your question is answered is on page
156-163, where they also explain how many digits there are in the
repeating portion when a rational number's decimal expansion repeats
"forever".


A denominator D that has a terminating expansion has the property that
there is a number L such that 10-to-the-L is congruent to 0, modulo D.
(Hence 10 mod 2 = 0, 100 mod 4 = 0, 1000 mod 8 = 0, etc). Obviously
this generalizes to bases other than 10.


For denominator P, the length of the first cycle is the smallest
number L with 10-to-the-L congruent to 1, modulo P. They provide the
result that if P is prime, all cycles have the same length (i.e., for
a given prime denominator, the cycles will have the same length no
matter what the numerator. The cycle length need not be P-1, but it
will always divide P-1.


So, there's a start.


David


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.