In practice, you probably want to stop the loop early
Just a note, for slow learners like me, that otherwise one always gets amazingly correct and on the same scale amazingly useless result :-):
>perl rat.pl 0.49420098210293
0: 0 / 1 = 0 (-0.5)
2: 1 / 2 = 0.5 (0.006)
42: 42 / 85 = 0.4941176470588235 (-8e-005)
1: 43 / 87 = 0.4942528735632184 (5e-005)
1: 85 / 172 = 0.4941860465116279 (-1e-005)
1: 128 / 259 = 0.4942084942084942 (8e-006)
1: 213 / 431 = 0.494199535962877 (-1e-006)
3: 767 / 1552 = 0.494201030927835 (5e-008)
8: 6349 / 12847 = 0.4942009807737215 (-1e-009)
4: 26163 / 52940 = 0.4942009822440498 (1e-010)
2: 58675 / 118727 = 0.4942009820849512 (-2e-011)
3: 202188 / 409121 = 0.4942009821055385 (3e-012)
2: 463051 / 936969 = 0.4942009821029298 (-2e-016)
4869: 2254797507 / 4562511182 = 0.49420098210293 (8e-021)
5: 11274450586 / 22813492879 = 0.49420098210293 (-2e-021)
1: 13529248093 / 27376004061 = 0.49420098210293 (5e-023)
27: 376564149097 / 761965602526 = 0.49420098210293 (-2e-024)
1: 390093397190 / 789341606587 = 0.49420098210293 (1e-025)
13: 5447778312567 / 11023406488157 = 0.49420098210293 (-9e-028)
9: 49420098210293 / 100000000000000 = 0.49420098210293 (0)
Another surprising note, this little program produces more precise and more 'beautiful' (shorter) approximation, than a built-in verb for same purpose in my latest toy:
2 x: 0.49420098210293
2993521666234 6057296069093
(cf. 463051/936969), and changing comparison tolerance (with 9!:19) doesn't help