mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
#687648 from Robert Schuppenies: use classic division.
This commit is contained in:
parent
e91fcbdf69
commit
2a9b9cbea0
12 changed files with 33 additions and 33 deletions
|
@ -197,7 +197,7 @@ def recvfile_real(local, remote, name):
|
||||||
dt = t2-t1
|
dt = t2-t1
|
||||||
print size, "bytes in", round(dt), "seconds",
|
print size, "bytes in", round(dt), "seconds",
|
||||||
if dt:
|
if dt:
|
||||||
print "i.e.", int(size/dt), "bytes/sec",
|
print "i.e.", size//dt, "bytes/sec",
|
||||||
print
|
print
|
||||||
remote._recv(id) # ignored
|
remote._recv(id) # ignored
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Packer:
|
||||||
def pack_fstring(self, n, s):
|
def pack_fstring(self, n, s):
|
||||||
if n < 0:
|
if n < 0:
|
||||||
raise ValueError, 'fstring size must be nonnegative'
|
raise ValueError, 'fstring size must be nonnegative'
|
||||||
n = ((n+3)/4)*4
|
n = ((n + 3)//4)*4
|
||||||
data = s[:n]
|
data = s[:n]
|
||||||
data = data + (n - len(data)) * '\0'
|
data = data + (n - len(data)) * '\0'
|
||||||
self.buf = self.buf + data
|
self.buf = self.buf + data
|
||||||
|
@ -164,7 +164,7 @@ class Unpacker:
|
||||||
if n < 0:
|
if n < 0:
|
||||||
raise ValueError, 'fstring size must be nonnegative'
|
raise ValueError, 'fstring size must be nonnegative'
|
||||||
i = self.pos
|
i = self.pos
|
||||||
j = i + (n+3)/4*4
|
j = i + (n+3)//4*4
|
||||||
if j > len(self.buf):
|
if j > len(self.buf):
|
||||||
raise EOFError
|
raise EOFError
|
||||||
self.pos = j
|
self.pos = j
|
||||||
|
|
|
@ -17,14 +17,14 @@ def fact(n):
|
||||||
# Treat even factors special, so we can use i = i+2 later
|
# Treat even factors special, so we can use i = i+2 later
|
||||||
while n%2 == 0:
|
while n%2 == 0:
|
||||||
res.append(2)
|
res.append(2)
|
||||||
n = n/2
|
n = n//2
|
||||||
# Try odd numbers up to sqrt(n)
|
# Try odd numbers up to sqrt(n)
|
||||||
limit = sqrt(float(n+1))
|
limit = sqrt(float(n+1))
|
||||||
i = 3
|
i = 3
|
||||||
while i <= limit:
|
while i <= limit:
|
||||||
if n%i == 0:
|
if n%i == 0:
|
||||||
res.append(i)
|
res.append(i)
|
||||||
n = n/i
|
n = n//i
|
||||||
limit = sqrt(n+1)
|
limit = sqrt(n+1)
|
||||||
else:
|
else:
|
||||||
i = i+2
|
i = i+2
|
||||||
|
|
|
@ -104,7 +104,7 @@ def main():
|
||||||
|
|
||||||
def showbar(dict, title):
|
def showbar(dict, title):
|
||||||
n = len(title)
|
n = len(title)
|
||||||
print '='*((70-n)/2), title, '='*((71-n)/2)
|
print '='*((70-n)//2), title, '='*((71-n)//2)
|
||||||
list = []
|
list = []
|
||||||
keys = dict.keys()
|
keys = dict.keys()
|
||||||
keys.sort()
|
keys.sort()
|
||||||
|
@ -126,7 +126,7 @@ def show(dict, title, maxitems):
|
||||||
if len(dict) > maxitems:
|
if len(dict) > maxitems:
|
||||||
title = title + ' (first %d)'%maxitems
|
title = title + ' (first %d)'%maxitems
|
||||||
n = len(title)
|
n = len(title)
|
||||||
print '='*((70-n)/2), title, '='*((71-n)/2)
|
print '='*((70-n)//2), title, '='*((71-n)//2)
|
||||||
list = []
|
list = []
|
||||||
keys = dict.keys()
|
keys = dict.keys()
|
||||||
for key in keys:
|
for key in keys:
|
||||||
|
|
|
@ -83,7 +83,7 @@ def makestatus(name, thisuser):
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
#
|
#
|
||||||
if totaljobs:
|
if totaljobs:
|
||||||
line = '%d K' % ((totalbytes+1023)/1024)
|
line = '%d K' % ((totalbytes+1023)//1024)
|
||||||
if totaljobs <> len(users):
|
if totaljobs <> len(users):
|
||||||
line = line + ' (%d jobs)' % totaljobs
|
line = line + ' (%d jobs)' % totaljobs
|
||||||
if len(users) == 1:
|
if len(users) == 1:
|
||||||
|
@ -95,7 +95,7 @@ def makestatus(name, thisuser):
|
||||||
line = line + ' (%s first)' % thisuser
|
line = line + ' (%s first)' % thisuser
|
||||||
else:
|
else:
|
||||||
line = line + ' (%d K before %s)' % (
|
line = line + ' (%d K before %s)' % (
|
||||||
(aheadbytes+1023)/1024, thisuser)
|
(aheadbytes+1023)//1024, thisuser)
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
#
|
#
|
||||||
sts = pipe.close()
|
sts = pipe.close()
|
||||||
|
|
|
@ -110,7 +110,7 @@ def test():
|
||||||
def tuple(list):
|
def tuple(list):
|
||||||
if len(list) == 0: return ()
|
if len(list) == 0: return ()
|
||||||
if len(list) == 1: return (list[0],)
|
if len(list) == 1: return (list[0],)
|
||||||
i = len(list)/2
|
i = len(list)//2
|
||||||
return tuple(list[:i]) + tuple(list[i:])
|
return tuple(list[:i]) + tuple(list[i:])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -17,11 +17,11 @@ def main():
|
||||||
p, q, k = k*k, 2L*k+1L, k+1L
|
p, q, k = k*k, 2L*k+1L, k+1L
|
||||||
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
||||||
# Print common digits
|
# Print common digits
|
||||||
d, d1 = a/b, a1/b1
|
d, d1 = a//b, a1//b1
|
||||||
while d == d1:
|
while d == d1:
|
||||||
output(d)
|
output(d)
|
||||||
a, a1 = 10L*(a%b), 10L*(a1%b1)
|
a, a1 = 10L*(a%b), 10L*(a1%b1)
|
||||||
d, d1 = a/b, a1/b1
|
d, d1 = a//b, a1//b1
|
||||||
|
|
||||||
def output(d):
|
def output(d):
|
||||||
# Use write() to avoid spaces between the digits
|
# Use write() to avoid spaces between the digits
|
||||||
|
|
|
@ -92,9 +92,9 @@ def mkdate((year, month, day)):
|
||||||
# even though that day never actually existed and the calendar
|
# even though that day never actually existed and the calendar
|
||||||
# was different then...
|
# was different then...
|
||||||
days = year*365 # years, roughly
|
days = year*365 # years, roughly
|
||||||
days = days + (year+3)/4 # plus leap years, roughly
|
days = days + (year+3)//4 # plus leap years, roughly
|
||||||
days = days - (year+99)/100 # minus non-leap years every century
|
days = days - (year+99)//100 # minus non-leap years every century
|
||||||
days = days + (year+399)/400 # plus leap years every 4 centirues
|
days = days + (year+399)//400 # plus leap years every 4 centirues
|
||||||
for i in range(1, month):
|
for i in range(1, month):
|
||||||
if i == 2 and calendar.isleap(year):
|
if i == 2 and calendar.isleap(year):
|
||||||
days = days + 29
|
days = days + 29
|
||||||
|
|
|
@ -91,7 +91,7 @@ def sendportcmd(s, f, port):
|
||||||
hostname = gethostname()
|
hostname = gethostname()
|
||||||
hostaddr = gethostbyname(hostname)
|
hostaddr = gethostbyname(hostname)
|
||||||
hbytes = string.splitfields(hostaddr, '.')
|
hbytes = string.splitfields(hostaddr, '.')
|
||||||
pbytes = [repr(port/256), repr(port%256)]
|
pbytes = [repr(port//256), repr(port%256)]
|
||||||
bytes = hbytes + pbytes
|
bytes = hbytes + pbytes
|
||||||
cmd = 'PORT ' + string.joinfields(bytes, ',')
|
cmd = 'PORT ' + string.joinfields(bytes, ',')
|
||||||
s.send(cmd + '\r\n')
|
s.send(cmd + '\r\n')
|
||||||
|
|
|
@ -35,15 +35,15 @@ class Tkhanoi:
|
||||||
|
|
||||||
# Add background bitmap
|
# Add background bitmap
|
||||||
if bitmap:
|
if bitmap:
|
||||||
self.bitmap = c.create_bitmap(width/2, height/2,
|
self.bitmap = c.create_bitmap(width//2, height//2,
|
||||||
bitmap=bitmap,
|
bitmap=bitmap,
|
||||||
foreground='blue')
|
foreground='blue')
|
||||||
|
|
||||||
# Generate pegs
|
# Generate pegs
|
||||||
pegwidth = 10
|
pegwidth = 10
|
||||||
pegheight = height/2
|
pegheight = height//2
|
||||||
pegdist = width/3
|
pegdist = width//3
|
||||||
x1, y1 = (pegdist-pegwidth)/2, height*1/3
|
x1, y1 = (pegdist-pegwidth)//2, height*1//3
|
||||||
x2, y2 = x1+pegwidth, y1+pegheight
|
x2, y2 = x1+pegwidth, y1+pegheight
|
||||||
self.pegs = []
|
self.pegs = []
|
||||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||||
|
@ -57,14 +57,14 @@ class Tkhanoi:
|
||||||
self.tk.update()
|
self.tk.update()
|
||||||
|
|
||||||
# Generate pieces
|
# Generate pieces
|
||||||
pieceheight = pegheight/16
|
pieceheight = pegheight//16
|
||||||
maxpiecewidth = pegdist*2/3
|
maxpiecewidth = pegdist*2//3
|
||||||
minpiecewidth = 2*pegwidth
|
minpiecewidth = 2*pegwidth
|
||||||
self.pegstate = [[], [], []]
|
self.pegstate = [[], [], []]
|
||||||
self.pieces = {}
|
self.pieces = {}
|
||||||
x1, y1 = (pegdist-maxpiecewidth)/2, y2-pieceheight-2
|
x1, y1 = (pegdist-maxpiecewidth)//2, y2-pieceheight-2
|
||||||
x2, y2 = x1+maxpiecewidth, y1+pieceheight
|
x2, y2 = x1+maxpiecewidth, y1+pieceheight
|
||||||
dx = (maxpiecewidth-minpiecewidth) / (2*max(1, n-1))
|
dx = (maxpiecewidth-minpiecewidth) // (2*max(1, n-1))
|
||||||
for i in range(n, 0, -1):
|
for i in range(n, 0, -1):
|
||||||
p = c.create_rectangle(x1, y1, x2, y2, fill='red')
|
p = c.create_rectangle(x1, y1, x2, y2, fill='red')
|
||||||
self.pieces[i] = p
|
self.pieces[i] = p
|
||||||
|
@ -101,10 +101,10 @@ class Tkhanoi:
|
||||||
|
|
||||||
# Move it towards peg b
|
# Move it towards peg b
|
||||||
bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
|
bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
|
||||||
newcenter = (bx1+bx2)/2
|
newcenter = (bx1+bx2)//2
|
||||||
while 1:
|
while 1:
|
||||||
x1, y1, x2, y2 = c.bbox(p)
|
x1, y1, x2, y2 = c.bbox(p)
|
||||||
center = (x1+x2)/2
|
center = (x1+x2)//2
|
||||||
if center == newcenter: break
|
if center == newcenter: break
|
||||||
if center > newcenter: c.move(p, -1, 0)
|
if center > newcenter: c.move(p, -1, 0)
|
||||||
else: c.move(p, 1, 0)
|
else: c.move(p, 1, 0)
|
||||||
|
|
|
@ -168,7 +168,7 @@ class Card:
|
||||||
self.group = Group(canvas)
|
self.group = Group(canvas)
|
||||||
|
|
||||||
text = "%s %s" % (VALNAMES[value], suit)
|
text = "%s %s" % (VALNAMES[value], suit)
|
||||||
self.__text = CanvasText(canvas, CARDWIDTH/2, 0,
|
self.__text = CanvasText(canvas, CARDWIDTH//2, 0,
|
||||||
anchor=N, fill=self.color, text=text)
|
anchor=N, fill=self.color, text=text)
|
||||||
self.group.addtag_withtag(self.__text)
|
self.group.addtag_withtag(self.__text)
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ class Solitaire:
|
||||||
|
|
||||||
def animatedmoveto(self, card, dest):
|
def animatedmoveto(self, card, dest):
|
||||||
for i in range(10, 0, -1):
|
for i in range(10, 0, -1):
|
||||||
dx, dy = (dest.x-card.x)/i, (dest.y-card.y)/i
|
dx, dy = (dest.x-card.x)//i, (dest.y-card.y)//i
|
||||||
card.moveby(dx, dy)
|
card.moveby(dx, dy)
|
||||||
self.master.update_idletasks()
|
self.master.update_idletasks()
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Array:
|
||||||
if self.speed == "fastest":
|
if self.speed == "fastest":
|
||||||
msecs = 0
|
msecs = 0
|
||||||
elif self.speed == "fast":
|
elif self.speed == "fast":
|
||||||
msecs = msecs/10
|
msecs = msecs//10
|
||||||
elif self.speed == "single-step":
|
elif self.speed == "single-step":
|
||||||
msecs = 1000000000
|
msecs = 1000000000
|
||||||
if not self.stop_mainloop:
|
if not self.stop_mainloop:
|
||||||
|
@ -320,7 +320,7 @@ class ArrayItem:
|
||||||
return outcome
|
return outcome
|
||||||
|
|
||||||
def position(self):
|
def position(self):
|
||||||
x1 = (self.index+1)*XGRID - WIDTH/2
|
x1 = (self.index+1)*XGRID - WIDTH//2
|
||||||
x2 = x1+WIDTH
|
x2 = x1+WIDTH
|
||||||
y2 = (self.array.maxvalue+1)*YGRID
|
y2 = (self.array.maxvalue+1)*YGRID
|
||||||
y1 = y2 - (self.value)*YGRID
|
y1 = y2 - (self.value)*YGRID
|
||||||
|
@ -349,7 +349,7 @@ def interpolate(oldpts, newpts, n):
|
||||||
res = [tuple(oldpts)]
|
res = [tuple(oldpts)]
|
||||||
for i in range(1, n):
|
for i in range(1, n):
|
||||||
for k in range(len(pts)):
|
for k in range(len(pts)):
|
||||||
pts[k] = oldpts[k] + (newpts[k] - oldpts[k])*i/n
|
pts[k] = oldpts[k] + (newpts[k] - oldpts[k])*i//n
|
||||||
res.append(tuple(pts))
|
res.append(tuple(pts))
|
||||||
res.append(tuple(newpts))
|
res.append(tuple(newpts))
|
||||||
return res
|
return res
|
||||||
|
@ -359,7 +359,7 @@ def interpolate(oldpts, newpts, n):
|
||||||
|
|
||||||
def uniform(array):
|
def uniform(array):
|
||||||
size = array.getsize()
|
size = array.getsize()
|
||||||
array.setdata([(size+1)/2] * size)
|
array.setdata([(size+1)//2] * size)
|
||||||
array.reset("Uniform data, size %d" % size)
|
array.reset("Uniform data, size %d" % size)
|
||||||
|
|
||||||
def distinct(array):
|
def distinct(array):
|
||||||
|
@ -429,7 +429,7 @@ def quicksort(array):
|
||||||
j = j-1
|
j = j-1
|
||||||
continue
|
continue
|
||||||
array.message("Choosing pivot")
|
array.message("Choosing pivot")
|
||||||
j, i, k = first, (first+last)/2, last-1
|
j, i, k = first, (first+last)//2, last-1
|
||||||
if array.compare(k, i) < 0:
|
if array.compare(k, i) < 0:
|
||||||
array.swap(k, i)
|
array.swap(k, i)
|
||||||
if array.compare(k, j) < 0:
|
if array.compare(k, j) < 0:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue