Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
$ say 3602879701896397/36028797018963968 == 0.100000000000000006;

Have they changed the spec ?
> say 3602879701896397/36028797018963968 == 0.100000000000000006; False
I have:
$ raku -v Welcome to Rakudo(tm) v2021.03. Implementing the Raku(tm) programming language v6.d. Built on MoarVM version 2021.03.
If the RHS is a rational, then it's fairly easy to show that 3602879701896397/36028797018963968 != 100000000000000006/1000000000000000000.
(A/B == C/D if and only if A*D == B*C. In this case, A*D ends in zero and B*C ends in 8 so the equivalence cannot possibly hold.)

If the RHS is a double, then it's correct that 3602879701896397/36028797018963968 == 0.100000000000000006.
However, the 3 doubles assigned (respectively) the 3 values 0.100000000000000006, 0.10000000000000001 and 0.1 are all exactly the same. So we find, as expected:
> say 3602879701896397/36028797018963968 == 0.100000000000000006e0; True > say 3602879701896397/36028797018963968 == 0.10000000000000001e0; True > say 3602879701896397/36028797018963968 == 0.1e0; True
I've long been curious about the mindset that has created the rational/double arithmetic on raku, and I had thought (hoped) it might be a simple task to see how it all fits together.
Alas no, and I'm starting to see that I'm going to have to locate and work through the relevant documentation if I ever want to understand it.


In reply to Re^2: [Raku] Arcane treatment of doubles and rationals by syphilis
in thread [Raku] Arcane treatment of doubles and rationals by syphilis

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-10-20 10:55 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (81 votes). Check out past polls.