Perl has implemented the POSIX functions of ceil() and floor() for a long time. ceil() and floor(). This link is more than a decade old.

This behavior is shocking to you because you think in base 10. The computer thinks in base 2 and a number that may appear to you to only take a finite amount of digits in base 10, but it may take an infinite number of digits in base 2.

This issue exists in C, Perl, Java and all languages that do computations in base 2, native binary machine code. For business applications (e.g. accounting), special hardware and software packages exist that do math in BCD, Binary Coded Decimal - that is an encoding where 4 binary bits only represents 0-9 instead of 0-15 like in binary.

If you take an accounting class and we do straight line depreciation of 1/3 per year over 3 years. At "the end of day" these "round down" things come back to haunt us and one way to handle this is that the last year gets just slightly more depreciation so that the total depreciation works out to the initial value of the asset. These are "real world" considerations and they matter - heck anything having to do with money matters!


In reply to Re: shocking imprecision by Marshall
in thread shocking imprecision by xrmb

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.