Yes you could do everything as a rational.

Thing about fractions is that you end up doing quite a lot of work finding hcf of the denominators.

An indefinite precision decimal fixed point arithmetic would, essentially, be an "bigrat", but all denominators would be powers of 10. That would mean, of course, that 1/3 would have a "representation" error -- but we are at least used to that.

The advantage of a fixed (but large) precision decimal floating point would be that functions like exp() and log() etc. (which do appear in financial calculations) would be more straightforward... as would any arithmetic involving widely different scales of numbers. You have to understand the effect of rounding...

Now that I've looked, I see that there is Math::BigFloat which is decimal (though that small fact doesn't exactly leap out at you). I see it is implemented using BigInt for the significands, and allows quite fine control over the precision. So I'll go away now.


In reply to Re^7: Getting different results with $var++ and $var += 1 by gone2015
in thread Getting different results with $var++ and $var += 1 by splicer

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.