Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Reasons for Using Perl 6

by Anonymous Monk
on Jan 03, 2018 at 16:20 UTC ( #1206609=note: print w/replies, xml ) Need Help??


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

Yes, I will probably convert 132511/43 into a FP approximate value only if I need it as a human to estimate the magnitude, but not if my aim is to store the value in a computer and if I am given the technical means to store it as a rational.
The trouble with rationals is that the denominators keep growing. If you add 132511/43 and 27/67 and 1024/853, you've got 7577076638/2457493. Pretty soon you'll hit Perl6's built-in limit of 64 bits in the denominator, and it will switch to binary floating point automatically. Rationals do not solve the problem, but they do make things a lot more complicated.

(Yes, I'm aware that you can sometimes cancel out common factors between the numerator and denominator. No, this does not solve your problem.)

Replies are listed 'Best First'.
Re^7: Reasons for Using Perl 6
by Laurent_R (Canon) on Jan 03, 2018 at 20:01 UTC
    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.
      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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206609]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-06-19 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (114 votes). Check out past polls.

    Notices?