Do you know where your variables are? PerlMonks

### comment on

 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":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2021-01-27 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The STEM quote I most wish I'd made is:

Results (300 votes). Check out past polls.

Notices?