Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

n1vux (1492)

  (email not shown publicly) ... x.cgi?BillRicker
AOL IM: n1vux (Add Buddy, Send Message)
Yahoo! ID: n1vux (Add User, Send Message)

Only started with Perl4 and Perl5 in 1995. I was doing AWK etc for 12 years before that, and resisted switching. I've been doing OO since before C++ hit bigtime, with Objective-C and SmallTalk, so I really like the (no longer new) Perl5 OO style; and the Lispish Map style is also an old friend. What do I hack with Perl? All data that passes my way; systems monitoring scripts at $DayJob, weather data at night, and I cheat on NPR word puzzles. Member: [] [] /. LinkedIn []

N1VUX is my FCC-issued ham radio callsign.

Journal of n1vux (1492)

Saturday January 28, 2006
11:51 PM

Fun with Math::BigFloat and #perl

[ #28505 ]
I'm not usually an irc-nik, but I had fun tonight thanks to trying #perl on freenode. Pete_I posted a query for help with a "borked" program to compute Pi, and was ignored by the folks busy debating VI vs Emacs. (Do they do that daily or only on weekends?)

Hoping to be helpful, and out of curiosity -- I have always loved math, or at least since 2nd grade -- I clicked on his paste link. It referenced a website by someone I vaguely knew and certainly knew of 20 years ago when our research areas overlapped and have seen in the math literature since then, David H. Bailey. I remember noting his breakthrough on direct computation of digits of pi (in HEX), and his website to search for your name (in ascii) in Pi, but I had not yet played with his new algorithm. I had played with searching for strings of DIGITS in a pre-computed Pi of a mere 10_000 decimal digits with Perl last year. Dave's 5-bit ascii search in Pi searches 4_000_000_000 bits, 5 orders longer.

So I asked Pete_I what was wrong, but the only reply was a punch-line just the facts ma'am from a sniper. So after a short break, I asked him by direct message. It seemed his coding of the algorithm was losing precision after 10-15 decimal places, even though it was using Math::BigFloat.

After several false starts -- and reading the academic paper three links into DBH's pages -- I found that, unless we used the modular arithmetic hacks DBH used to avoid using arbitrary precision packages, we needed to increase the default precision and use BigFloat for all numeric variables, not just $pi. In the process, I refactored the code to compute the sequence of the series first and then evaluate the polynomial by the classical add-and-divide technique.

My final code differs from Pete_I's code primarily in reading in, printing, and subtracting from the comparison value. (And commenting out Acme::Comment ;-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.