0

I am trying to find out the square root of a number. But the numbers are large. Python gives the error

OverflowError: int too large to convert to float

My code is here:

number=pow(255,200)-10000000 sqrt=math.sqrt(number) 

i tried it with the decimal class but it doesn't work. How to handle these large numbers in python?

1
  • the Decimal class it can handle it with its .sqrt method: (pow(Decimal(255),200)-10000000).sqrt() = Decimal('4.508354347658170012443202806E+240') Commented Aug 20, 2016 at 3:53

1 Answer 1

1
import math pow(10, 1/2 * math.log10(pow(255,200)-10000000)) 

The result is: 4.508354347658245e+240

Sign up to request clarification or add additional context in comments.

1 Comment

Its working fine but it cannot assign to a variable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.