Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Which "use" statements in a module do "bubble up" to the callers?

by AnomalousMonk (Chancellor)
on Aug 31, 2017 at 16:48 UTC ( #1198430=note: print w/replies, xml ) Need Help??


in reply to Re^4: Which "use" statements in a module do "bubble up" to the callers?
in thread Which "use" statements in a module do "bubble up" to the callers? [SOLVED]

... 22/7 is ... slightly better ... but 4*atan2(1,1) is much better.

And my favorite, 355/113, "slide-rule pi", is right in between the two!


Give a man a fish:  <%-{-{-{-<

  • Comment on Re^5: Which "use" statements in a module do "bubble up" to the callers?
  • Download Code

Replies are listed 'Best First'.
Re^6: Which "use" statements in a module do "bubble up" to the callers?
by BillKSmith (Vicar) on Sep 01, 2017 at 16:33 UTC
    Even better: Use M_PI from POSIX instead of PI. Oops, that does not illustrate the scope problem.
    Bill

      I had a vague recollection of a 4-digit/4-digit pi rational approximation that was better than 355/113, but a quick search of the Interwebs shows the next (slightly) better approximations come with 5-digit/5-digit ratios. I must have been thinking of some other rat-app.


      Give a man a fish:  <%-{-{-{-<

        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) ...
      Remember kids, always get the value of π from the same source. That way, if it changes, you won't have to hunt for it all over the place!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1198430]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-01-18 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (208 votes). Check out past polls.

    Notices?