Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: decimal to fraction by vr
in thread decimal to fraction by no_slogan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2018-06-23 00:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?



      Results (124 votes). Check out past polls.

      Notices?