For a Science Fair project, I am testing how your choice of programming language could affect performance. I am doing this by making scripts in Java, Ruby, Perl, and Python to calculate Pi to the 100 millionth decimal place. I'm starting with Perl, since I'm most familiar with Perl. However, this brings an interesting problem to the table. I need to round Pi to the 100 millionth digit in Perl, but as far as I can see, Perl has no good rounding method for this situation. There's only stuff like
use Math::Round;
$rounded = nearest(0.1, $numb);
And that's a bit of a problem, since I don't want to sit at my computer typing 100 million zeros. As far as I know, sprintf and printf aren't any better; plus, they have that annoying half to even thing. Can anyone help out?
P.S. I'm planning to use the Chudnovsky Formula, if it matters to anyone.
I don't think any programming language can natively do what you are asking. Even bignum libraries like Math::BigRat (default 40 digits) and Math::Bignum cannot do 100 million digits.
To make it happen, you will have to create your own custom way to represent such big numbers and how to round them.
Think about the problem in another way. You need to round to 100 million (1E8) digits but you don't need to process all 1E8 digits in one go to do that.
Instead,
However, if the goal is to test relative performance of languages by generating 1E8 digits of Pi then why bother focus on the rather artificial constraint of rounding that number. If you use the same algorithm then any language should produce the same result. And you have a 50% chance of generating a rounded number anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With