Techniques for perserving long decimals in programs?

Feb 2010
168
20
Columbus, Ohio, USA
I'm trying to write a program for a project which approximates the values of \(\displaystyle e\) and \(\displaystyle \pi\) in the visual basic langue. Lets just look at \(\displaystyle \pi\), I'm approximating it with the two following integrals:

\(\displaystyle \pi = 4\int_0^1\sqrt{1-x^2} dx\) which is based off of the area of a quarter of a circle with radius one and center \(\displaystyle (0, 0)\). And I used:

\(\displaystyle \pi = 2\int_0^1\sqrt{1 + \frac{x^2}{1-x^2} } dx\) which is based of the integral distance formula and the relationship \(\displaystyle \pi = \frac{Circumferance}{Diameter}\)

Which integral is best to use in approximating pi in a computer program? And also, visual basic rounds off calculations (after a considerable decimal place), but I would like to be able to display many correct decimal places of \(\displaystyle \pi\) and \(\displaystyle e\). When I plug in large numbers of rectangles my computer freezes for a few seconds and on larger inputs it simply states "overload". Is there a way to break up the rectangles into parts and express the decimal as a further extended expansion by some seperate technique? So I can approximate to an even greater accuracy without my computer freezing and without visual basic rounding it off?

Thanks in advance
 

Ackbeet

MHF Hall of Honor
Jun 2010
6,318
2,433
CT, USA
Off the top of my head, I'd say your first formula is better. Addition and multiplication preserves or increases sig figs, but division and subtraction decreases sig figs. Do you have to approximate \(\displaystyle \pi\) with those formulas, or can you choose whichever one you want? For example, there are some arctan approximations that are really nice, if I remember correctly.
 

undefined

MHF Hall of Honor
Mar 2010
2,340
821
Chicago
I haven't programmed in VB, but it looks like if you are using VB .NET then you can import Extreme.Mathematics and then use the BigFloat class for arbitrary precision floating-points. If you can't import this, then maybe you can find a package online to do the same thing.

Also I don't have experience with approximating pi, but I believe Taylor expansion is better than Riemann sums. You could try Wikipedia or MathWorld or just internet searches for other ideas on how to approximate.
 
Feb 2010
168
20
Columbus, Ohio, USA
Off the top of my head, I'd say your first formula is better. Addition and multiplication preserves or increases sig figs, but division and subtraction decreases sig figs. Do you have to approximate \(\displaystyle \pi\) with those formulas, or can you choose whichever one you want? For example, there are some arctan approximations that are really nice, if I remember correctly.
I do not have to use these formulas, these are just the only formulas I could come up with that would return an approximation of pi (short of constructing a 96 sided-regular polygon). Could you give me this arctan formula and just give a short description of how pi arises from it (unless pi is a directly equated, as in pi = arctan formula)

Thanks
 

undefined

MHF Hall of Honor
Mar 2010
2,340
821
Chicago
I do not have to use these formulas, these are just the only formulas I could come up with that would return an approximation of pi (short of constructing a 96 sided-regular polygon). Could you give me this arctan formula and just give a short description of how pi arises from it (unless pi is a directly equated, as in pi = arctan formula)

Thanks
See here. Also here. The internet is your friend..
 

Ackbeet

MHF Hall of Honor
Jun 2010
6,318
2,433
CT, USA
One of the ones I was thinking of is Equations 16 and 17 on this page.