git://git.novaco.in
/
p2pool.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
working ... sorry for bad log messages\!
[p2pool.git]
/
p2pool
/
util
/
math.py
1
from __future__ import division
2
3
def median(x, use_float=True):
4
# there exist better algorithms...
5
y = sorted(x)
6
left = (len(y) - 1)//2
7
right = len(y)//2
8
sum = y[left] + y[right]
9
if use_float:
10
return sum/2
11
else:
12
return sum//2
13
14
def shuffled(x):
15
x = list(x)
16
random.shuffle(x)
17
return x
18
19
def shift_left(n, m):
20
# python: :(
21
if m < 0:
22
return n >> -m
23
return n << m
24
25
def clip(x, (low, high)):
26
if x < low:
27
return low
28
elif x > high:
29
return high
30
else:
31
return x