From 5b92e4ff83f51351a58a24d5e03da558da11557c Mon Sep 17 00:00:00 2001 From: Michael Winter Date: Wed, 1 Apr 2026 16:47:45 +0200 Subject: [PATCH] Fix calculate_cents - use simple math.log2 instead of broken bit_length logic --- webapp/server.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/webapp/server.py b/webapp/server.py index 2ae6a6e..fc4f40d 100644 --- a/webapp/server.py +++ b/webapp/server.py @@ -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)