The truncation problem you mention with large decimal numbers is a hardware(platform) issue. Its because of the way floating point math is done, its simulated really. The FPU is a processor/set of optimized operations that do integer math behind the scenes.

Floating point numbers need to be represented in binary, but not just the number itself. Things like whether they're positive or negative, and their power(decimal position).

Standardized schemes are used internally for doing this, but each time the computer encounters a floating point number it needs to digest/squish it down into the special binary format. So one floating point number(i.e. 1.234) is represented with a few binary numbers(values) - the number, its power, and sign. Its during this conversion process that things get truncated. Depending upon the bit width of the FPU(as you mentioned), the conversion process will differ in the amount of truncation that needs to be done. I believe the computer doesn't do any rounding(just truncation), but this truncation could mess up any rounding you tried to do within your code.

To avoid the truncation you can do everything with whole numbers(integer values), its just more work. Any floating point math equation can be solved using whole numbers(multiplying everything out to get rid of the decimal).

There is a similar problem with large integers when the values surpass what can be natively reprsented by the bit width(if its 32bit, something greater than 2^32) But thats much much less of an issue...

DISCLAIMER: This is all simplified..I'm not into electrical engineering, not an expert in the area. Just taking a shot at answering the question :)
hope this all helps - blueAdept

In reply to Re: Rounding Errors by blueAdept
in thread Rounding Errors by Anonymous Monk

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.