$ /usr/bin/python2 simple.py 200 > out2.pbm
$ /opt/src/Python-3.10.1/bin/python3 simple.py 200 > out3.pbm
$ cmp out2.pbm out3.pbm
out2.pbm out3.pbm differ: byte 304, line 3
The python2 output is correct. The python3 output is incorrect.
Here is a correct .pbm output file.
simple.py is
import sys
w = h = x = y = bit_num = 0
byte_acc = 0
i = 0; iterations = 50
limit = 2.0
Zr = Zi = Cr = Ci = Tr = Ti = 0.0
w = int(sys.argv[1])
h = w
sys.stdout.write("P4\n%d %d\n" % (w, h))
for y in range(h):
for x in range(w):
Zr = Zi = 0.0
Cr = (2.0 * x / w - 1.5); Ci = (2.0 * y / h - 1.0)
for i in range(iterations):
Tr = Zr*Zr - Zi*Zi + Cr
Ti = 2*Zr*Zi + Ci
Zr = Tr; Zi = Ti
if Zr*Zr+Zi*Zi > limit*limit:
break
if Zr*Zr+Zi*Zi > limit*limit:
byte_acc = (byte_acc << 1) | 0x00
else:
byte_acc = (byte_acc << 1) | 0x01
bit_num += 1
if bit_num == 8:
sys.stdout.write(chr(byte_acc))
byte_acc = 0
bit_num = 0
elif x == w - 1:
byte_acc = byte_acc << (8-w%8)
sys.stdout.write(chr(byte_acc))
byte_acc = 0
bit_num = 0
What changed that could cause the different output?