Skip to content

Instantly share code, notes, and snippets.

@iuriguilherme
Last active January 26, 2024 21:15
Show Gist options
  • Save iuriguilherme/2f53b88e56c0233468a78d96cb4ee5d9 to your computer and use it in GitHub Desktop.
Save iuriguilherme/2f53b88e56c0233468a78d96cb4ee5d9 to your computer and use it in GitHub Desktop.
The 987654321 / 123456789 thing
"""The 987654321 / 123456789 thing"""
import mpmath
import sys
offset = 1e0
limit = 1e1
last = 8
if len(sys.argv) > 1:
if sys.argv[1].find('e') < 0:
limit = float(f"1e{int(sys.argv[1]):.0f}")
offset = float(f"1e{(int(sys.argv[1]) - 1):.0f}")
else:
limit = float(f"{sys.argv[1]}")
if int(sys.argv[1][0]) == 1:
offset = float(f"9e{int(sys.argv[1][2]) - 1}")
else:
offset = float(f"{int(sys.argv[1][0]) - 1}{sys.argv[1][1:]}")
if len(sys.argv) > 2:
if sys.argv[2].find('e') < 0:
offset = float(f"1e{int(sys.argv[2]):.0f}")
else:
offset = float(f"{sys.argv[2]}")
def stress(dps) -> None:
"""Tries to overflow"""
mpmath.mp.dps = dps
print(f"BEGIN dps = {dps}")
try:
last = mpmath.mp.mpf('987654321') / mpmath.mp.mpf('123456789')
print(last)
with open("last.txt", "w+") as f:
f.write(str(last))
except MemoryError:
raise
finally:
print(f"END dps = {dps}")
print(f"BEGIN ALL limit {limit}, offset {offset}")
try:
for dps in range(int(offset), int(limit)):
try:
stress(dps)
except MemoryError:
print(f"Memory error at {dps}. Lower offset from {offset}")
break
except KeyboardInterrupt:
pass
print(f"LAST = {last}")
print(f"END ALL limit {limit}, offset {offset}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment