in reply to Re^2: Non-integer print output???
in thread Non-integer print output???
That particular result is absolute rubbish.
Not at all. In fact, your snippet proves that the correct result is returned. You think the incorrect result is returned because you incorrectly assume print doesn't perform any rounding.
Why are we so ready to settle for a half-arsed floating point approximation when an exact floating point (or integer) representation is available ?
It's not an approximation. The result is 100% exact in this case. (Powers of two literally require only 1 bit of precision, and that bit isn't even stored.) There are cases where exponentiation could produce more accurate numbers using ints than floats on a build with 64 bit ints. But this is eclipsed by the number of cases that are more precise using floats (e.g. 2**0.5), and it's also eclipsed by the number of cases that are only possible using floats (e.g. 2**65).
It looks like you are raising your own question about why scientific notation is used by print or why it rounds, but the question asked was about why exponentiation returns "a float instead of a 64-bit number". That has nothing to do with how print stringifies floats. Sure, that could be improved, but that's a different question.
Upd: Rewritten
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Non-integer print output???
by syphilis (Archbishop) on Sep 13, 2021 at 10:32 UTC |