http://www.perlmonks.org?node_id=1206625


in reply to Re^6: Reasons for Using Perl 6
in thread Reasons for Using Perl 6

The trouble with rationals is that the denominators keep growing.
Yes and no. It is true that there are cases where they do grow (but do you often add numbers like 132511/43 and 27/67 and 1024/853?), but there are many more cases where they don't. If you add or subtract many numbers in decimal format which most of us use everyday (monetary amount, physical measures made in the metric system, etc.) with, say two to five decimal places (or more), and the denominators will not grow and will often be a power of 10 (possibly multiplied by a power of 2 or a power of 5, something that can easily be brought back to a power of 10 by adjusting the numerator by the same factor). So in such cases, you'll never reach the 64-bit limit.

Replies are listed 'Best First'.
Re^8: Reasons for Using Perl 6
by Anonymous Monk on Jan 03, 2018 at 20:38 UTC
    If you add or subtract many numbers in decimal format which most of us use everyday...
    If what you really want is BigDecimal, why bother with a rational type at all?
      I know about a BigDecimal class in Java, but I don't know about anything like that in Perl. Is there anything like that? Or perhaps you mean something derived from BigInt or BigRat?
        I know about a BigDecimal class in Java, but I don't know about anything like that in Perl

        Math::decNumber provides arbitrary precision decimal arithmetic.

        Cheers,
        Rob
        Math::BigFloat seems to be doing decimal floating point, not binary, but I don't have much experience with it. There are a couple of other decimal modules on CPAN, but I know even less about them. The trouble with Perl's standard multiple-precision math modules is that they're overcomplicated and have some surprising behavior.