|[3 earlier articles]|
|Re: rational to floating point firstname.lastname@example.org (Thant Tessman) (2003-03-14)|
|Re: rational to floating point email@example.com (Joachim Durchholz) (2003-03-14)|
|Re: rational to floating point firstname.lastname@example.org (Arthur J. O'Dwyer) (2003-03-14)|
|Re: rational to floating point email@example.com (Glen Herrmannsfeldt) (2003-03-14)|
|Re: rational to floating point firstname.lastname@example.org (2003-03-14)|
|Re: rational to floating point Peter-Lawrence.Montgomery@cwi.nl (2003-03-14)|
|Re: rational to floating point email@example.com (John Stracke) (2003-03-14)|
|From:||John Stracke <firstname.lastname@example.org>|
|Date:||14 Mar 2003 11:54:25 -0500|
|Posted-Date:||14 Mar 2003 11:54:25 EST|
Thant Tessman wrote:
> And I think that this in turn implies that if and only if
> gcd(d,b) is 1 and 'd' is not 1, then the original rational number can
> only be represented by an infinite stream of digits.
No, that doesn't work; consider writing 5/6 in base 10 (0.8333...).
The logic you want is that it's a repeating decimal if d has any prime
factors which do not divide into b. I'm not sure offhand of an
efficient way to do this test, though.
However, you might consider that a better way to cope with repeating
decimals is to print them as repeating decimals. A useful tidbit to
remember is that l, the length of the repeating part, divides d-1 (for
example, 1/7 is 0., where the 6 digits in  repeat). Given
that, you may be able to come up with a good algorithm for the printing.
|John Stracke | http://www.thibault.org |HTML OK |
|Francois Thibault |========================================|
|East Kingdom |So what's the gene for belief in genetic|
Return to the
Search the comp.compilers archives again.