|
-
Feb 1st, 2001, 08:09 PM
#1
Thread Starter
Fanatic Member
I wanted to have more presicion than just using Math.PI, but i can't figure out how to do it (partially). Someone else hepled me get started, but their code didn't work entirely, as I just keep getting the same two numbers. This si what I have:
Code:
package piApplet;
public class piApplet
{
public static void main(String[] args)
{
long factorial = 1;
int i = 1;
double errMax = 1E-8, piOld = 1.0, piNew = 1.0, error = 1.0;
while (error > errMax)
{
factorial = factorial * i;
piNew = piOld + (1.0 / (double)factorial) * Math.pow(-1, i);
error = Math.abs(piNew - piOld);
i++;
piOld = piNew;
System.out.println(piOld);
}
System.out.println("pi = " +piNew);
}
}
Can anyone help?
-
Feb 4th, 2001, 05:12 PM
#2
PowerPoster
Maybe you should do this genius:
Code:
package pi;
public class pi
{
public static void main(String[] args)
{
long denom = 1;
int i = 1;
double errMax = 1E-5, piOld = 4.0, piNew = 4.0, error = 1.0;
while (error > errMax)
{
denom = denom + 2;
piNew = piOld + (4.0/(double)denom) * Math.pow(-1,i);
error = Math.abs(piNew - piOld);
i++;
piOld = piNew;
}
System.out.println(piNew);
}
}
-
Feb 4th, 2001, 07:42 PM
#3
Thread Starter
Fanatic Member
Maybe I should, who knows?
Alcohol & calculus don't mix.
Never drink & derive.
-
Feb 4th, 2001, 07:51 PM
#4
PowerPoster
That code looks fimiluar don't it?
-
Feb 4th, 2001, 08:23 PM
#5
Thread Starter
Fanatic Member
Alcohol & calculus don't mix.
Never drink & derive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|