Continued Fraction Approximations
I wrote this Python script to find increasingly accurate rational approximations to any number using convergents and continued fraction representations. Below is the output for √2 ≈ 1.4142, π ≈ 3.14159, and Euler's constant e ≈ 2.718.
>>> convergents2floats(convergents(contfrac(2**.5)), 2**.5)
Fraction Approximation Difference
1/1 1.00000000000000000 -0.41421356237309515
3/2 1.50000000000000000 0.08578643762690485
7/5 1.39999999999999991 -0.01421356237309523
17/12 1.41666666666666674 0.00245310429357160
41/29 1.41379310344827580 -0.00042045892481934
99/70 1.41428571428571437 0.00007215191261922
239/169 1.41420118343195256 -0.00001237894114259
577/408 1.41421568627450989 0.00000212390141474
1393/985 1.41421319796954315 -0.00000036440355200
3363/2378 1.41421362489486957 0.00000006252177442
8119/5741 1.41421355164605478 -0.00000001072704037
Target: 1.41421356237309515
>>> convergents2floats(convergents(contfrac(math.pi)), math.pi)
Fraction Approximation Difference
3/1 3.00000000000000000 -0.14159265358979312
22/7 3.14285714285714279 0.00126448926734968
333/106 3.14150943396226401 -0.00008321962752911
355/113 3.14159292035398252 0.00000026676418940
103993/33102 3.14159265301190249 -0.00000000057789062
104348/33215 3.14159265392142117 0.00000000033162806
208341/66317 3.14159265346743677 -0.00000000012235635
312689/99532 3.14159265361893647 0.00000000002914335
833719/265381 3.14159265358107787 -0.00000000000871525
1146408/364913 3.14159265359140383 0.00000000000161071
4272943/1360120 3.14159265358938899 -0.00000000000040412
Target: 3.14159265358979312
>>> convergents2floats(convergents(contfrac(math.e)), math.e)
Fraction Approximation Difference
2/1 2.00000000000000000 -0.71828182845904509
3/1 3.00000000000000000 0.28171817154095491
8/3 2.66666666666666652 -0.05161516179237857
11/4 2.75000000000000000 0.03171817154095491
19/7 2.71428571428571441 -0.00399611417333068
87/32 2.71875000000000000 0.00046817154095491
106/39 2.71794871794871806 -0.00033311051032703
193/71 2.71830985915492951 0.00002803069588442
1264/465 2.71827956989247310 -0.00000225856657199
1457/536 2.71828358208955212 0.00000175363050703
2721/1001 2.71828171828171827 -0.00000011017732682
Target: 2.71828182845904509