I have authored a web application RADIX, which for further optimisation needs to calculate the maximum number of places necessary to precisely represent the fraction part of a number of base $m$ in base $n$ (assuming a precise conversion is possible).
For example, assuming $f$ represents $15$ in base $64$, how many fraction digits are required to represent the number $f.f$ in base $10$?
I know that the maximum number of digits needed to represent the integer part can be calculated by taking the ceiling of $\log_{10}(64)$ * the number of digits (correct me if I'm wrong), but what about the fractional part of the number?
$f.f$ is $15.234375$ in base $10$, so one fraction numeral in base $64$ seems to require up to $6$ fraction digits in base $10$ to represent it, but is there a way I can calculate that in advance for any two bases?
At the moment I am using $\log_2(m)$ * the number of fraction digits of the number in base m, which happens to give just the right answer for the example above, i.e. $\log_2(64)$ is $6$, but it causes me to calculate to an unnecessarily high number of places for other conversions.
Update:
Example code, based on ShreevatsaR's expression for d in terms of m and n using prime factorisation.
# assumes float division
m = 288 # base of the number to be converted
n = 270 # base the number is to be converted to
i = 2
d = 0
while m > 1 and n > 1:
e = 0
f = 0
while m % i == 0:
e += 1
m /= i
while n % i == 0:
f += 1
n /= i
# if i is a prime factor of both m and n
if e != 0 and f != 0 and e / f > d:
d = math.ceil( e / f )
i += 1
if d == 0:
# No fraction part of a number of base m has a finite
# representation when converted to base n, and vice versa
else:
# A maximum of d * r fraction digits is needed to represent the
# fraction part of a number of base m in base n, where r is the
# number of fraction digits of the number in base m