python - Unable to calculate exact cube root -


this question has answer here:

i'm solving cryptographic problem,

i need cube root of 4.157786362549383e+37, gives me 3464341716380.1113

using

x = x ** (1. / 3) 

i thought weird @ first, did try:

x=1000 print(x) x= pow(x,1/3) print(x) 

but got 9.99999998

i have tried somewhere else. got same result. there wrong? how can calculate true cube root?

due floating-point arithmetic, hard represent.

using decimal resolves still problematic in numbers, , allows rounding integrals. try using decimal so:

>>> (1000 ** (decimal(1)/3)).to_integral_exact() decimal('10') 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -