Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
If you want arbitrary precision rational arithmetic, you can use a FatRat

I didn't know about FatRats (yes, I know very little about perl6) - so I had a bit of a play (on rakudo-star-2017.07) and encountered confusing results:
> my $x = 1.111111111111111111111.FatRat; my $y = 1.111111111111111111 +111.Rat; $x - $y 0 > $x == $y True > say $x 1.111111111111111111111 > say $y 1.11111111111111111604544 >
On the bases that $x-$y==0 and $x==$y one is led to believe that $x and $y are exactly equivalent.
Yet, say() presents us with different values.

Are the 2 rationals equivalent ?
If so, then why does say() output different values ?
If not, then why do both $x-$y==0 and $x==$y evaluate as "True" ?

Interestingly, 1.11111111111111111604544 is the value of the double 1.1111111111111111 (16 decimal places) rounded to 23 decimals:
C:\>perl -le "printf '%.22e\n', 1.1111111111111111;" 1.1111111111111111604544e+000\n
Perhaps this ties in with:
> my $x = 1.111111111111111111111.FatRat; my $y = 1.1111111111111111.N +um; $x - $y 0 > $x == $y True
How does one coerce perl6 into displaying the actual numerator and denominator of these rationals ?

Cheers,
Rob

In reply to Re^3: Small Perl 6 discoveries II, Rats by syphilis
in thread [Perl6] Small discoveries I, __DATA__ by holli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found