Dear David, Lon and everybody else who helped me,

thanks for your help. I really appreciate it.

Best regards,

Sven

P.S.: As soon as I have a piece of code which works fast, I will send you all a final answer incl. the code


On Saturday, Nov 2, 2002, at 20:33 Europe/Berlin, David Kirol wrote:

Sven,
You might look at:

use strict;
my $pi = 0;
my $y = 1;
my $sign = 1;;
my $i;
for($i = 0; $i < 1000000;$i++) {
$pi += $sign/$y;
$y += 2;
$sign = $sign > 0 ? -1 : 1;
}
$pi *= 4;
print"Approximation of Pi: $pi\n";

But consider:
my $cpi = 2 * atan2(1, 0);
print"$cpi\n";
Unless you -must- use an infinite series, there is almost alway a better
way...
Consider the million iterations above (and the error) against the builtin.
HTH
David

-----Original Message-----
From: Sven Bentlage [mailto:root@;svenbentlage.de]
Sent: Saturday, November 02, 2002 11:43 AM
To: [EMAIL PROTECTED]
Subject: Calculate PI


Hi everyone!

I am trying to write a program calculating pi.
The formula I would like to use is
pi = 4x( (1/1) - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) .... )
or
$pi = 4x ( (1/$y) - ....)

My problem is how to raise the $y by 2 and how to switch "+" and "-"
while calculating the formula.


For any hints on how to to it or where to find any documentation about
that, I`d be really grateful.

Thanks for your support in advance.

Cheers,

Sven


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to