http://qs321.pair.com?node_id=11123149


in reply to Re^4: int() function
in thread int() function

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