Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I know it's confusing

I don't find it so.

But if you stuff a number with more than 15 decimals into a double you'll have loss anyway.

One thing I can guarantee is that if you limit yourself to 15 decimal digits, you will experience the loss of not being able to assign the full range of "double" values.
As an example:
C:\perl -le "printf '%a', 1.41421356237312;" 0x1.6a09e667f3c3dp+0 C:\>perl -le "printf '%a', 1.41421356237313;" 0x1.6a09e667f3c6ap+0
Between 0x1.6a...c3d and 0x1.6a...c6a there exists 45 doubles with distinct, precise values. (c6a - c3d == 2d == 45 in base 10)
But you can't assign to any of those 45 values if you limit yourself to assigning 15-digit values. (For some of those values 16 digits will suffice, but you'll never need more than 17 digits.)
Also, for each of those 45 values, perl will output that they are either 1.41421356237312 or 1.41421356237313.
That's 45 precise, distinct, unique values - for which perl will display only 2 values.
Perl is making itself look ridiculous for the sake of saving 2 digits of precision.

And I doubt it's better in JS or python

Python2 was crap, but python3 (as I've already mentioned in this thread) is exemplary:
$ python3 -c "print(0.14)" 0.14 $ python3 -c "print(1.4 / 10)" 0.13999999999999999 $ python3 -c "print(2 ** 0.5)" 1.4142135623730951
Python3 will always output the minimum number of decimal digits needed to preserve the uniqueness of the given value. And, last time I checked, raku was outputting exactly the same as python3 - for "doubles", anyway.

Not sure what happens with javascript - I've no experience with it.

Cheers,
Rob

In reply to Re^5: int() function by syphilis
in thread int() function by geoperl

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 examining the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found