Wed Jun 22 12:25:50 MDT 2011 zooko@zooko.com * mathutil: diagnostics about what inputs to next_power_of_k() are causing a NaN-related exception diff -rN -u old-1.8.2/src/allmydata/util/mathutil.py new-1.8.2/src/allmydata/util/mathutil.py --- old-1.8.2/src/allmydata/util/mathutil.py 2011-06-22 12:27:25.121490999 -0600 +++ new-1.8.2/src/allmydata/util/mathutil.py 2011-06-22 12:27:25.463490999 -0600 @@ -28,7 +28,7 @@ def is_power_of_k(n, k): return k**int(math.log(n, k) + 0.5) == n -def next_power_of_k(n, k): +def next_power_of_k_math(n, k): if n == 0: x = 0 else: @@ -38,6 +38,20 @@ else: return k**x +def next_power_of_k_alt(n, k): + p = 1 + while p < n: + p *= k + return p + +def next_power_of_k(n, k): + try: + return next_power_of_k_math(n, k) + except ValueError, e: + print "XXX n: %s :: %s, k: %s :: %s, next_power_of_k_alt: %s" % (n, type(n), k, type(k), next_power_of_k_alt(n, k)) + e.args = tuple(e.args + (n, k, next_power_of_k_alt(n, k))) + raise + def ave(l): return sum(l) / len(l)