Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if python int is too large to convert to float

Is there any way to check if a long integer is too large to convert to a float in python?

like image 753
ad126 Avatar asked Jul 10 '10 17:07

ad126


1 Answers

>>> import sys
>>> sys.float_info.max
1.7976931348623157e+308

Actually, if you try to convert an integer too big to a float, an exception will be raised.

>>> float(2 * 10**308)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C double
like image 180
kennytm Avatar answered Sep 30 '22 07:09

kennytm