Godtone (talk | contribs)
added some python 3 code i think should be fine for experimenting with/further building on, needs extra proofreading just in case though
Godtone (talk | contribs)
m My Python 3 code: renaming for clarity
Line 500: Line 500:
def iv(n, d, p=None): # provides automatic reduction to simplest form
def iv(n, d, p=None): # provides automatic reduction to simplest form
return unfact(fact( (n,d),p ),p)
return unfact(fact( (n,d),p ),p)
def as_float(r,p=None):
def as_float(x, p=None):
if type(r)==list:
if type(x)==list: # monzo (factored)
uf = unfact(r, p)
uf = unfact(x, p)
return uf[0] / uf[1]
return uf[0] / uf[1]
elif type(r)==tuple:
elif type(x)==tuple: # ratio (unfactored)
return r[0] / r[1]
return x[0] / x[1]
else:
else: # assumed to already be a float (or integer)
return r
return x


# Converts a prime factorisation into a prettier and potentially
# Converts a prime factorisation into a prettier and potentially