projects
/
tahoe-lafs
/
tahoe-lafs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
d407e4f
)
add mathutil.next_power_of_k() and mathutil.ave()
author
Zooko O'Whielacronx
<zooko@zooko.com>
Thu, 1 Feb 2007 22:55:26 +0000
(15:55 -0700)
committer
Zooko O'Whielacronx
<zooko@zooko.com>
Thu, 1 Feb 2007 22:55:26 +0000
(15:55 -0700)
src/allmydata/util/mathutil.py
patch
|
blob
|
history
diff --git
a/src/allmydata/util/mathutil.py
b/src/allmydata/util/mathutil.py
index fa58ecc06dcc1f4b9a462802fe3b8d4669ca2b72..afcb31214e98193952944e84a9055e84ba10eac7 100644
(file)
--- a/
src/allmydata/util/mathutil.py
+++ b/
src/allmydata/util/mathutil.py
@@
-34,3
+34,18
@@
def pad_size(n, k):
def is_power_of_k(n, k):
return k**int(math.log(n, k) + 0.5) == n
+
+def next_power_of_k(n, k):
+ if n == 0:
+ x = 0
+ else:
+ x = int(math.log(n, k) + 0.5)
+ r = k**x
+ if k**x < n:
+ return k**(x+1)
+ else:
+ return k**x
+
+def ave(l):
+ return sum(l) / len(l)
+