When using sqrt
from the library math
, before it proceeds to square root it, it will convert the value to a float.
If we manually try to convert the 10**2000
to a float, it also triggers an error
>>> float(10**2000)
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-14-6ac81f63106d> in <module>
----> 1 math.sqrt(10**2000)
OverflowError: int too large to convert to float
If we were speaking of a big number, but with the square equals or less than 308, the Decimal
module would do the work as follows
>>> from decimal import Decimal
>>> Decimal(math.sqrt(10**308))
Decimal('10000000000000000369475456880582265409809179829842688451922778552150543659347219597216513109705408327446511753687232667314337003349573404171046192448274432')
However, as the number is way square is way bigger than 308, in this case, 2000, one would have to do as follows
>>> from decimal import Decimal
>>> Decimal(10**2000).sqrt()
Decimal('1.000000000000000000000000000E+1000')
Let's see the output if one tries to convert the Decimal(10**2000)
to float
>>> float(Decimal(10**2000))
inf
One might also use the decimal module when working with factorials, as they tend to get large really fast.