Rational approximations of π using continued fractions:
my $pi = 4*atan2(1,1); my $x = $pi; my $h1 = 0; my $h0 = 1; my $k1 = 1; my $k0 = 0; for (1 .. 5) { my $c = int($x); for my $d (($c+1)/2 .. $c) { my ($h, $k) = ($d * $h0 + $h1, $d * $k0 + $k1); my $val = $h / $k; my $err = $val - $pi; print "$h / $k = $val ($err)\n"; } ($h0, $h1) = ($c * $h0 + $h1, $h0); ($k0, $k1) = ($c * $k0 + $k1, $k0); $x -= $c or last; $x = 1 / $x; } __END__ 2 / 1 = 2 (-1.14159265358979) 3 / 1 = 3 (-0.141592653589793) 13 / 4 = 3.25 (0.108407346410207) 16 / 5 = 3.2 (0.0584073464102071) 19 / 6 = 3.16666666666667 (0.0250740130768734) 22 / 7 = 3.14285714285714 (0.00126448926734968) 179 / 57 = 3.14035087719298 (-0.00124177639681067) 201 / 64 = 3.140625 (-0.000967653589793116) 223 / 71 = 3.14084507042254 (-0.000747583167258092) 245 / 78 = 3.14102564102564 (-0.000567012564152147) 267 / 85 = 3.14117647058824 (-0.000416183001557879) 289 / 92 = 3.14130434782609 (-0.000288305763706198) 311 / 99 = 3.14141414141414 (-0.000178512175651679) 333 / 106 = 3.14150943396226 (-8.32196275291075e-05) 355 / 113 = 3.14159292035398 (2.66764189404967e-07) 52163 / 16604 = 3.14159238737654 (-2.66213257216208e-07) 52518 / 16717 = 3.14159239097924 (-2.62610550638698e-07) ...

In reply to Re^8: Which "use" statements in a module do "bubble up" to the callers? (way OT) by Anonymous Monk
in thread Which "use" statements in a module do "bubble up" to the callers? [SOLVED] by Nocturnus

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, details, 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, summary, 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.