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

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?

Replies are listed 'Best First'.
Re^10: Reasons for Using Perl 6
by syphilis (Archbishop) on Jan 05, 2018 at 06:03 UTC
    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
      OK, thank you, I had not heard about that module before.
        And installing Math::decNumber is as easy as:
        cpan -i Math::decNumber
        There's no need to worry about first locating and downloading the decNumber library as it ships with the module - and the functionality is automatically built into the Math::decNumber dll/so as part of the build process.

        All very easy, passes its test suite, and works well:
        C:\> perl -MMath::decNumber="d_" -le "print d_(0.3) - d_(0.2) - d_(0.1 +);" 0.0 C:\>perl -MMath::decNumber="d_" -le "print sqrt(d_(3));" 1.732050807568877293527446341505872

        No trig functions, unfortunately.

        Cheers,
        Rob
Re^10: Reasons for Using Perl 6
by Anonymous Monk on Jan 03, 2018 at 21:37 UTC
    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.
      The trouble with Perl's standard multiple-precision math modules is that they're overcomplicated and have some surprising behaviour.

      In my limited experience with these modules I've found them to be well behaved as long as they're loaded with 'use Math::BigInt', 'use Math::BigFloat', 'use Math::BigRat'.
      I regard this as the sane way to load these modules.
      Start loading them with 'use bignum', 'use bigint', etc. (which I regard as the insane way) and they can get a bit tricky - I think largely because variables might not always be what you think they are.

      If you have some examples of surprising behaviour when loading is done "sanely" then it's probably worth presenting them here.
      (But, please, not buried in this thread. Instead create a new thread.)

      I regard the major drawback to the standard multi-precision math modules as being their speed. However, speed is not always terribly important.

      And, yes, those modules are doing decimal arithmetic.

      Another decimal module that might be worth trying is Math::decNumber. I haven't got around to testing it yet, as it requires the decNumber C library - but trying it out is definitely on my todo list.

      Cheers,
      Rob
        Start loading them with 'use bignum', 'use bigint', etc. (which I regard as the insane way) and they can get a bit tricky
        The insanity of bignum and bigint has its tendrils wrapped around Math::BigInt in ways that are not easy to fix without breaking backwards compatibility.
        I regard the major drawback to the standard multi-precision math modules as being their speed.
        I almost included that in my list of problems, but I think the slowness is due in large part to the overcomplexity of supporting bignum craziness.