# Determine whether the decimal expansion of a rational number is infinite

This may be a naive question but I would like to know whether we can determine if a fraction (say $1/3$) will produce a rational number with an infinite number of digits after the decimal when computed (without actually computing it).

Of course computers cannot store such rational numbers accurately and they are difficult to detect after calculations have been performed and the result truncated.

Similar to how we can perform integral calculations on improper fractions to get their remainder, I wonder if we can do something similar to determine if a proper fraction will compute to an irrational number.

• What? a fraction is by definition rational. it can't be irrational. – Frank Mar 9 '15 at 11:48

## 2 Answers

A rational number has terminating decimal expansion if the denominator (in lowest terms) has prime factors only $2$ or $5$ or both. Any other factors in the denominator yield a non-terminating decimal expansion.

Examples $$\frac{1}{1024} = 0.0009765625\quad\text{(exactly)}$$ terminates because $1024 = 2^{10}$.

$$\frac{1}{6} = 0.16666666666\cdots$$ is non-terminating, because $6=2\cdot3$ has a prime factor $3$.

• Thank you for that explanation. On a related note, here is question about decimal/binary representation of such numbers if you are interested. – Raheel Khan Mar 9 '15 at 15:20

An irrational number is one that cannot be written as a fraction. Examples are $\sqrt{2}$ and $\pi$.
Perhaps you mean the decimal stops, for example $3/4=0.75$. A fraction's decimal stops if the denominator is a power of $2$, (say 8), a power of $5$, (say 25), or their product, here 200.
Real numbers on computer are commonly stored in binary, which is base 2 instead of base ten. That is exact, and stops only if the denominator is a power of two.

• Thanks. I had the terminology incorrect. Yes I am referring to rational numbers (where the decimal part is infinitely repeating such as $1/3$). So for base 10, any fraction whose denominator is not a power of 2 or 5, would produce a never-ending sequence of digits after the decimal. Am I understanding that correctly? – Raheel Khan Mar 9 '15 at 12:19
• A power of two times a power of 5, Raheel. – Gerry Myerson Mar 9 '15 at 12:21
• @GerryMyerson: Thanks. Just to confirm, testing the denominator to be a power of 2 or 5 OR like you said a product of a power of 2 and a power of 5. Now I'm wondering if I would have to iterate to test this (similar to how we find factors of large numbers). Or is determining the same possible with a single calculation? Please let me know if you feel this should be posted as a new question. – Raheel Khan Mar 9 '15 at 12:29
• Iteration's the way to go, Raheel. You can't just look at a 20-digit number and tell whether it's a power of 2. – Gerry Myerson Mar 9 '15 at 22:14