# Math Help - Techniques for perserving long decimals in programs?

1. ## Techniques for perserving long decimals in programs?

I'm trying to write a program for a project which approximates the values of $e$ and $\pi$ in the visual basic langue. Lets just look at $\pi$, I'm approximating it with the two following integrals:

$\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 $(0, 0)$. And I used:

$\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 $\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 $\pi$ and $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?

2. 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 $\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.

3. 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.

4. Originally Posted by Ackbeet
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 $\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

5. Originally Posted by mfetch22
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..

6. One of the ones I was thinking of is Equations 16 and 17 on this page.