# Techniques for perserving long decimals in programs?

• Jun 9th 2010, 07:19 AM
mfetch22
Techniques for perserving long decimals in programs?
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?

• Jun 9th 2010, 07:27 AM
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 $\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.
• Jun 9th 2010, 07:40 AM
undefined
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.
• Jun 9th 2010, 07:43 AM
mfetch22
Quote:

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 $\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
• Jun 9th 2010, 07:52 AM
undefined
Quote:

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..
• Jun 9th 2010, 07:54 AM
Ackbeet
One of the ones I was thinking of is Equations 16 and 17 on this page.