4 Replies - 78 Views - Last Post: 17 February 2009 - 11:27 PM

#1 Plus   User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Extended Pi

Posted 04 February 2009 - 07:42 AM

Description: how to use:
 const short* pi = ExtendPi(decimal_places);
 cout <<" "<< pi[0] <<'.';
 for(int i=1;i<decimal_places;i++)
     cout << pi[i];


/*
      function that take decimal places (10,20,30,~)
      for calculating Pi extended into power
      programmed by: khaled khunaifer [Plus]
*/

short* AdvancedPi(int PLACES=50){

  short Pi[PLACES]={3,1,4,0}   // 50 places of Pi

  long double P = ((22*(10^10))/7);  // maximize the arithmetic
  long int I= Pi; // integer part
  long double D = (Pi - I); // decimal part
 
  for(int j=0;j<PLACES/10;j++){
    for(int i=0;i<10;i++){
       Pi[9-i] = I%10;
       I /= 10;
    } // I is 0 now
    D *= (10^10);
    I = D;
    D -=I;
  }
  return Pi;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Extended Pi

#2 Plus   User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Re: Extended Pi

Posted 04 February 2009 - 07:42 AM

Description: how to use:
 const short* pi = ExtendPi(decimal_places);
 cout <<" "<< pi[0] <<'.';
 for(int i=1;i<decimal_places;i++)
     cout << pi[i];


modified*
/*
      function that take decimal places (10,20,30,~)
      for calculating Pi extended into power
      programmed by: khaled khunaifer [Plus]
*/

short* AdvancedPi(const int PLACES=50){

  short Pi[PLACES]={3,1,4,0}   // 50 places of Pi

  long long double P = ((22*(10^10))/7);  // maximize the arithmetic
  long long int I= Pi; // integer part
  long long double D = (Pi - I); // decimal part
 
  for(int j=0;j<PLACES/10;j++){
    for(int i=0;i<10;i++){
       Pi[9-i] = (short)(I%10); // modification
       I /= 10; // shift
    } // I is <zero> now
    D *= (10^10);
    I = D; // draw 10 digits to "extract"
    D -=I;
  }
  return Pi;
}


Was This Post Helpful? 0
  • +
  • -

#3 Plus   User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Re: Extended Pi

Posted 04 February 2009 - 07:44 AM

waiting for your comments ...
Was This Post Helpful? 0
  • +
  • -

#4 bszmyd   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 104
  • Joined: 09-February 09

Re: Extended Pi

Posted 17 February 2009 - 07:50 PM

Sorry...but you can't initialize a variable length array:
short Pi[PLACES]={3,1,4,0}; //No go
Convert a short* to a long:
short Pi[PLACES]={3,1,4,0};
Or return an address to something declared on the stack:
short Pi[PLACES]={3,1,4,0};
return Pi;
Nothing that can't be fixed however.
Was This Post Helpful? 0
  • +
  • -

#5 bszmyd   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 104
  • Joined: 09-February 09

Re: Extended Pi

Posted 17 February 2009 - 07:51 PM

That second problem should read for short* to long is: long int I= Pi;
Was This Post Helpful? 0
  • +
  • -

#6 Plus   User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Re: Extended Pi

Posted 17 February 2009 - 11:27 PM

thank you for your help .. i'll modify the code,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1