On Sat, Sep 12, 2020 at 05:37:23PM -0700, Christopher Barker wrote:
On Sat, Sep 12, 2020 at 5:05 PM Steven D'Aprano <steve@pearwood.info> wrote:
IEEE-754 requires that float literals overflow to infinity.
sure, which means that, e.g. 1e100 * 1e300 would overflow to Inf.
But that doesn't say anything about interpreting a literal. I don't if C libs necessarily parse:
Sorry, I didn't explain correctly. What I attempted, but failed, to say is that the standard requires that if the float literal cannot be represented as a numeric value because it would overflow, then it should be interpreted as an infinity. So `1e300` can be represented as a double precision float, so that's what you get, but `1e1000` cannot be, it overflows, so you get infinity instead. This doesn't mean that the standard requires the parser to read the mantissa and exponent separately and actually perform a multiplication and power. I expect that the standard will require *correctly rounded* results. So for example, this literal rounds down to the largest possible finite float: py> 1.7976931348623158e+308 1.7976931348623157e+308 but this literal rounds up to infinity: py> 1.7976931348623159e+308 inf because the closest representable binary number to 1.79...159e+308 would overflow the available bits.
So that's what I'm wondering -- is there a standard that says the a too-large literal should overflow, and therefgor create and inf, rather than being an error.
Yep, that's what I'm saying :-) Or at least tried to say. -- Steve