Godtone
Joined 17 December 2020
m →My Python 3 code: fix convert() edgecase |
m →My Python 3 code: make default to not convert subharmonic to avoid unexpected behaviour |
||
| Line 596: | Line 596: | ||
return (k*k, k*k-1) | return (k*k, k*k-1) | ||
s = S | s = S | ||
def convert(x, totype, p=None): | def convert(x, totype, p=None, subharmonic=False): | ||
if totype==float: | if totype==float: | ||
return as_float(x,p) | return as_float(x,p) | ||
| Line 609: | Line 609: | ||
if len(fact_int(interval[1]))==1 or interval[1]==1: # if harmonic (denominator in 2-lim) | if len(fact_int(interval[1]))==1 or interval[1]==1: # if harmonic (denominator in 2-lim) | ||
return interval[0] | return interval[0] | ||
if len(fact_int(interval[0]))==1 or interval[0]==1: # if subharmonic (numerator in 2-lim) | if subharmonic and (len(fact_int(interval[0]))==1 or interval[0]==1): # if subharmonic (numerator in 2-lim) | ||
return interval[1] | return interval[1] | ||
elif subharmonic: | |||
raise TypeError("interval is not harmonic (/2^n) or subharmonic (2^n/)") | |||
else: | else: | ||
raise TypeError("interval is not harmonic (/2^n) | raise TypeError("interval is not harmonic (/2^n); note 2^n/ conversion to int is off by default (subharmonic=False)") | ||
if totype==tuple: | if totype==tuple: | ||
if type(x)==int: | if type(x)==int: | ||