2 ms·
An explanation of the following useful fact:A fraction p/q is equal to a finite length floating point number in base b <=> q divides b^n <=> the prime factors
by lovboat 11y ago
An explanation of the following useful fact:A fraction p/q is equal to a finite length floating point number in base b <=> q divides b^n <=> the prime factors of q are prime factors of b.
Proof if q divides b^n, then q * c = b^n => p/q = (p * c)/(q * c) = (p * c)/b^n = (p * c)e-n in base b.
Example: Express the fraction 7/18 (base 10), in base 60 and convert it to a floating point in base 60.
60 = 2^2 * 3^1 * 5^1, 18 = 2^1 * 3^2, look for c such that 18 * c is a power of 60. Observe that the factors of 60^2 all have exponents that are greater or equal than those of 18, so we can multiply 18 by the required factors to get (60^2). This way: 60^2 = (2^2 * 3 * 5)^2 = 2^4 * 3^2 * 5^2 = 18 * c = (2^1 * 3^2) * (2^3 * 3^0 * 5^2)= 18200, so we need to multiply by 200 the numerator and denominator of the initial fraction to get a new fraction whose denominator is a power of 60. Now 7/18 = (7 200)/(18 * 200) = 1400/(60^2) and 1400 = 23 * 60 + 20.
Finally 7/18 = 1400/(60^2) = 0.2360 in base 60.
We use the notation 00,01,02, ... 59 for the digits of base 60, so 2360 is a two digits number in base 60.
The asterisk used for multiplication is not shown in HN, don't know why.