# Precision C++

//Pi

//3/14/03

//---------------------------------------------------------------------------

#pragma hdrstop

#include <tapestry>

#include <iostream.h>

#include <math.h>

#include <conio.h>

#include <condefs.h>

//------------------------------------------------------------------

#pragma argsused

int main(int argc, char* argv[])

{

int x;

double pi, odd;

odd=3;

pi=1;

getch();

while(true)

{

if(x==0)

{

pi=pi+(1/odd);

}

else

{

pi=pi-(1/odd);

}

cout<<setprecision(100)<<pi*4<<endl;

if(x==0)

{

x=1;

}

else

{

x=0;

}

odd=odd+2;

}

getch();

return 0;

}

//---------------------------------------------------------------------------

## Comments

22,667memberAnyhow, here's a quick reference guide to the precision of various variable types:

short

A 2 byte integer (whole number values from -128 to 127).

int

A 4 byte integer (whole number values from -2,147,483,648 to 2,147,483,647).

long

4 or 8 byte integer (compiler dependent).

float

Single precision floating point number (compiler dependent, 7 digits or more).

double

Double precision floating point number (compiler dependent, 15 digits or more).

If you need *lots* more precision, I would suggest creating a class that uses an array to store digits and write some functions or overload the operators to do the math with it. I did this in an AP class long ago to create "bigint" and "bigfloat" variables. I'm sure there's some sample code or explanation around the web somewhere if you want to try implementing that.

5,012memberi used double as u can see but yet it still only shows to 16 decimal places

5,012memberOriginally posted by BradUm, did you leave something out? Your code looks incomplete.

Anyhow, here's a quick reference guide to the precision of various variable types:

short

A 2 byte integer (whole number values from -128 to 127).

int

A 4 byte integer (whole number values from -2,147,483,648 to 2,147,483,647).

long

4 or 8 byte integer (compiler dependent).

float

Single precision floating point number (compiler dependent, 7 digits or more).

double

Double precision floating point number (compiler dependent, 15 digits or more).

If you need *lots* more precision, I would suggest creating a class that uses an array to store digits and write some functions or overload the operators to do the math with it. I did this in an AP class long ago to create "bigint" and "bigfloat" variables. I'm sure there's some sample code or explanation around the web somewhere if you want to try implementing that.

thanks i'll check it out...i guess it really doesn't matter though, cuz the way i was figuring for pie would take a year probably to get to the 16 decimal places haha

i modified it a little and put it into a calculator and it didn't even get to the second decimal places haha