Re: Computing pi to nth terms?
From: Kraig (tsi1990_at_gmail.com)
Date: 09/21/04
- Next message: Ioannis Vranos: "Re: How stupid can a compiler be?!"
- Previous message: Victor Bazarov: "Re: Can I delete without calling the destructor ?"
- In reply to: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Next in thread: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Reply: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Reply: John Harrison: "Re: Computing pi to nth terms?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 20 Sep 2004 17:05:22 -0500
I am attempting to pass powers of two, from one to 16777216, to a
calculation that approximates pi for each respective power of two
previously mentioned. It's the second loop, the calculation of pi using
the int created in the first loop, that is proving problematic.
kraig
Kai-Uwe Bux wrote:
> Kraig wrote:
>
>
>>After much wringing of hands and pulling of hair, I have arrived at:
>>
>>#include <iostream>
>>#include (cmath>
>>using namespace std;
>>
>>int main()
>>{
>> double pi = 0;
>> double n = 0;
>> double x = 0;
>> double y = 0;
>>
>> for(n = 1; n <=16777216; n*=2)
>> {
>> for(x = 1; x <= (2*n - 1); y++)
>> {
>> pi = pow(1, ((y +1)) * (4/x);
>
>
> This sets pi to 1 since pow(1,whatever) is 1.
>
>
>> pi += pi;
>
>
> Now, pi is 2.
>
>
>> x+=2;
>
>
> And it exits the loop as two.
>
>> }
>> cout << "pi value using " << n << " terms is " << pi << " " "
>>\n";
>> }
>>return 0;
>>}
>>
>>This seems to basically work, but the values in output are not correct.
>
>
> Obviously you are trying to add the terms of some series for pi. Which one
> do you have in mind.
>
>
> Best
>
> Kai-Uwe Bux
- Next message: Ioannis Vranos: "Re: How stupid can a compiler be?!"
- Previous message: Victor Bazarov: "Re: Can I delete without calling the destructor ?"
- In reply to: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Next in thread: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Reply: Kai-Uwe Bux: "Re: Computing pi to nth terms?"
- Reply: John Harrison: "Re: Computing pi to nth terms?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|