[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Cyker Way
Cyker Way added the comment: Alright that helps. I guess I now understand what's happening here. Here are the two numbers in question: >>> M = int('1'*53+'0'*971, 2) >>> N = int('1'*53+'0'+'1'*970, 2) M is the largest number in binary64 range, while N is the largest number that does not

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Mark Dickinson
Change by Mark Dickinson : -- resolution: -> not a bug ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Mark Dickinson
Mark Dickinson added the comment: If we wanted to make a change, I think the part of the docs that I'd target would be this sentence: > a floating point number with the same value (within Python’s floating point > precision) is returned It's that "same value (within Python's floating point

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Mark Dickinson
Mark Dickinson added the comment: Yes, exactly: Python's intentionally following the normal IEEE 754 rules for rounding a value to the binary64 format using the round-ties-to-even rounding rule, as formalised in section 7.4 of IEEE 754-2019 (and quoted by @cykerway). These are the exact

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Cyker Way
Cyker Way added the comment: IEEE 754, 7.4 Overflow: > The overflow exception shall be signaled if and only if the destination > format’s largest finite number is exceeded in magnitude by what would have > been the rounded floating-point result (see 4) were the exponent range >

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Cyker Way
Cyker Way added the comment: If python's float strictly adheres to IEEE 754 binary64 (is that so?), then the problem may be caused by rounding. However, even in that case I still don't get the benefits of doing range check on a rounded input but not the input itself. Does IEEE 754 itself

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Steven D'Aprano
Steven D'Aprano added the comment: float(x) performs rounding. Only if the value after rounding is out of range is OverflowError raised. M + 1, when correctly rounded to the nearest even float, gives sys.float_info.max. Likewise for M+2, M+3 etc all the way to M+K where K equals 2**960

[issue46173] float(x) with large x not raise OverflowError

2021-12-24 Thread Cyker Way
New submission from Cyker Way : Acccording to: https://docs.python.org/3/library/functions.html#float >If the argument is outside the range of a Python float, an OverflowError > will be raised. It is well known that the maximum value in IEEE 754 binary64 format is: >>> M =