in reply to Re^5: Largest integer in 64-bit perl
in thread Largest integer in 64-bit perl
I disagree, at least if the operands were integer and the result is between max-float-precision and max-integer-precision (2**53 and 2**64 in our case) you can assume an integer was wanted.
Of course it's not trivial (if ever) to solve this generally for instance for $x=2**0.5 and $y=$x**2 since the square-root of 2 isn't rational.
Or even $x=2/3 and 27**$x == 9 because $x isn't loss-free in binary floats.
> Perhaps there should be an optional warning when it attempts to cast a result greater than 2**53 and less than 2**63 to an integer.
I think this should be part of a (bigger) pragma to address this.
for instance will Perl happily do this
DB<25> p 27**(2/3) 9 DB<26> p 27**(2/3) == 9 DB<27> printf "%.15f", 27**(2/3) 8.999999999999998 DB<28>
And before the Perl bashing hits in, Python isn't that much better
>>> 27**(2/3) 8.999999999999998 >>> 27**(2/3)==9 False >>>
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Largest integer in 64-bit perl (RFC)
by LanX (Saint) on Jun 02, 2025 at 21:18 UTC |