""" Ex. 2.19 from "A primer on..." Explore round-off errors by repeated calls to sqrt followed by the same number of **. Repeated square roots result in a number closer and closer to 1.0, and at some point (n~50) it becomes so close that the machine treats it as 1.0. Squaring 1.0 n times then just gives 1.0, and does not bring us back to 2.0. """ from math import sqrt for n in range(1, 60): r = 2.0 for i in range(n): r = sqrt(r) for i in range(n): r = r**2 print(f"{n:d} times sqrt and **2: {r:.16f}") """ Terminal> python repeated_sqrt.py 1 times sqrt and **2: 2.0000000000000004 2 times sqrt and **2: 1.9999999999999996 3 times sqrt and **2: 1.9999999999999996 4 times sqrt and **2: 1.9999999999999964 5 times sqrt and **2: 1.9999999999999964 6 times sqrt and **2: 1.9999999999999964 7 times sqrt and **2: 1.9999999999999714 ... 49 times sqrt and **2: 1.8682459487159784 50 times sqrt and **2: 1.6487212645509468 51 times sqrt and **2: 1.6487212645509468 52 times sqrt and **2: 1.0000000000000000 53 times sqrt and **2: 1.0000000000000000 54 times sqrt and **2: 1.0000000000000000 55 times sqrt and **2: 1.0000000000000000 56 times sqrt and **2: 1.0000000000000000 57 times sqrt and **2: 1.0000000000000000 58 times sqrt and **2: 1.0000000000000000 59 times sqrt and **2: 1.0000000000000000 """