Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OverflowError: long int too large to convert to float [duplicate]

I am trying to get the square root of a really large number yet I get the error: deltaSqrt = pow(delta,0.5) OverflowError: long int too large to convert to float

In my case delta is equal to:

5097524159124305711208346976972093994517918559319839193986818402316359809127198287961957143680580475665158537123211669238507145109614915183501090991258372348911567096198391700545859284651871243167548321047645673131690445736385731455226353155143585522960326625070327122610654962530056330418391386124854577090206480385789275416714631025155369128530489779489101162403615113670950177532664946764525175541382065187304866582420329863524912760301704277886453413147449455323732476653550495366827445013669840800229684474814585992820804300231060966713580804079322252173910482245551821723868004571663524727449944378683955667216

What should I do to get the square root of this number?

like image 852
Teodora Avatar asked Dec 26 '22 16:12

Teodora


1 Answers

Use decimal:

import decimal
>>> d = decimal.Decimal('5097524159124305711208346976972093994517918559319839193986818402316359809127198287961957143680580475665158537123211669238507145109614915183501090991258372348911567096198391700545859284651871243167548321047645673131690445736385731455226353155143585522960326625070327122610654962530056330418391386124854577090206480385789275416714631025155369128530489779489101162403615113670950177532664946764525175541382065187304866582420329863524912760301704277886453413147449455323732476653550495366827445013669840800229684474814585992820804300231060966713580804079322252173910482245551821723868004571663524727449944378683955667216')
>>> d.sqrt()
Decimal('7.139694782779097001143800270E+307')
like image 79
ndpu Avatar answered Mar 01 '23 23:03

ndpu