Results 1 to 9 of 9
I have to create this program using perl. I was also wondering if I could also find a way to have an input as well to I could calculate more ...
Enjoy an ad free experience by logging in. Not a member yet? Register.

 09162011 #1
 Join Date
 Apr 2011
 Posts
 4
Calculate Pi to 10,000 digits, then convert that number to binary form
 09172011 #2
 Join Date
 Dec 2007
 Posts
 35
I don't code anymore, but years back I had coded any input number, and the output would be in any base. It didn't make any difference if the output had to be binary, base 5, base 7, or octal, or hex it would do all of them.
It used the analogy of two analog wheels, which one rotated counterclockwise, and the other clockwise. It worked real nice, took very little calculations, and was quite accurate. Sorry, I can't give you any advise on using Perl, but perhaps you could use the same principle as the wheels for your project?
 09172011 #3
Answer 1, quick answer: use the @argv array to capture your command line parameters, one parameter with a value for example, another telling your program what you want it to do, e.g.
...
$what_to_do=$ARGV[0];
$value=$ARGV[1];
...
Answer 2, better answer: use the getopts() function, e.g. refer to www devdaily com/perl/perlgetoptscommandlineoptionsflagsinperl (replace the spaces with .)
Answer 3, best Answer: use Answer 2 then buy 'Learning Perl' and 'Programming Perl', both published by O'Reily
Hope this helps,
Chas
 09172011 #4
 Join Date
 Nov 2006
 Location
 near Berea, Kentucky (in a tipi)
 Posts
 47
Are you asking us to do your homework assignment for you?
If so, that's specifically against forum rules.
If not (or even if so), I am interested in your results.
I can program okay in Perl (I recommend O'Reilly's "Programming Perl"), yet I have no idea how one calculates the value of pi...
 09182011 #5
... ahh, pi, it must be one of those horrible Computer Science assignments...
 09182011 #6
 Join Date
 Aug 2011
 Posts
 16
Hi andrewrckt
What would you like us to do? I think, nobody will write the script for you. If you have an idea about how to do it, then start the editor and do it!
Or is it about how to implement the input? Use command line parameters it's propably the most easiest way.
It's propably a help to you to first implement the pi algo and then add additional functuallity to the script. So you have a base that you can extend.
Br
Haze
 09182011 #7
 Join Date
 Aug 2011
 Posts
 51
Try looing at the bignum module, setting the precision and select an algorithm to calculate pi.
 09202011 #8
 Join Date
 Apr 2011
 Posts
 4
this is not homework. I am doing this for pure curiosity. I have created a small program to take an input of a pi file of one million digits to convert to binary, but it will only go out to 2**64 so i can not convert pi efficiently.
use strict;
use Bit::Vector;
sub frac_bin {
my $frac = shift;
my $i = int( $frac * 2 ** 256 );
print "input: $frac\n";
my $vec = Bit::Vector>new_Dec( 256, $i );
my $result = $vec>to_Bin;
print "binary fraction: $result\n";
return $result;
}
my $bits;
$bits = frac_bin ( 0.141592653589793238462643383279502884197169399375 10582097494459230781640628620899862803482534211706 79 );
$bits = frac_bin ( 0.75 );
$bits = frac_bin ( 1 / 3 );
I do not ask for people to write something, but direction. I would love to figure out this question I have.
 09202011 #9
 Join Date
 Apr 2011
 Posts
 4
Also to add...i graduated last year with a Meteorology degree, thus I am no longer in that program. I would appreciate some help with this if you guys can.