One approach that could work would be to do error analysis as if you were approximating an infinite series. This is often covered in a second-semester calculus course (in the US), or at least touched on. Its been many years since i've actually done anything like this, but it was the first approach that came to mind.

In general, the idea is that you determine an reasonable upper bound that including another term (or digit in your case, which can be considered a term) will modify your answer by.

I will introduce a non-standard notation here:

Let PI(n) denote an approximation of the constant PI, truncated after n decimal places.

For example if you're dealing with PI, and have some approximation that has 'n' decimal places (n digits after the decimal), you know that including the next digit will affect the value of PI as:

Error <= PI(n+1) - PI(n) < (1/10)^n

So if you consider PI^2, you can do set something up like this:

Error <= [ PI(n+1) - PI(n) ]^2 < ((1/10)^n)^2
I think that doing that analysis directly is not exactly how you want to proceed, but i can't remember exactly what to do.

When i get home from work i'll have my math books available, instead of only these computer books. If i find anything more concrete, i'll post it from home.

I guess i can include this. If you find a series error analysis technique, you could use this series for PI:

PI = sum( i = 0 .. INF ) (-1 ^ i) / (2 * i + 1)
although that converges extremely slowly, and there are other better series that i cant think of right now.

I use the most powerful debugger available: print!

In reply to Re: OT: How much float precision needed for operation? by shemp
in thread OT: How much float precision needed for operation? by 5mi11er

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.