Fix calculate_cents - use simple math.log2 instead of broken bit_length logic
This commit is contained in:
parent
8f332fac52
commit
5b92e4ff83
|
|
@ -64,19 +64,11 @@ def parse_fraction(frac_str):
|
|||
|
||||
def calculate_cents(fraction_str):
|
||||
"""Calculate cents from fraction string."""
|
||||
import math
|
||||
|
||||
fr = parse_fraction(fraction_str)
|
||||
if fr <= 0:
|
||||
return 0
|
||||
return 1200 * (
|
||||
float(fr).bit_length()
|
||||
- 1
|
||||
+ (fr / (1 << (fr.bit_length() - 1)) - 1) / 0.6931471805599453
|
||||
if hasattr(fr, "bit_length")
|
||||
else 1200 * (float(fr).bit_length() - 1)
|
||||
)
|
||||
# Simpler: use log2
|
||||
import math
|
||||
|
||||
return 1200 * math.log2(fr)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue