0

I am going to calculate values of pi very precisely using python 3. For that, I first need a precise value of 426880*(10005)^0.5 now, using

>>> from decimal import *

>>> getcontext().prec = 100000

>>> Decimal(10005).sqrt()

i got the value of root of 10005 precisely upto 100,000 digits. But, when i try to multiply this by 426880 using:

>>> from decimal import *

>>> getcontext().prec = 1000000

>>> Decimal(426880) * Decimal(x)

x being the root of 10005 precisely calculated to 100,000 digits i only get a 28 digit number instead of the specified precision. How to multiply these values precisely?

zhangyangyu
  • 8,052
  • 2
  • 30
  • 42
Aayush Mahajan
  • 3,328
  • 6
  • 19
  • 31

2 Answers2

0

I think that your problem is that you are either saving x in a string and re-interpreting in or you have x from a previous calculation as a Decimal and you are doing Decimal(A_Decimal). If x is already a decimal then do not reinterpret it and if to save time you are saving if then use pickle or cpickle to save it as an object. BTW try to avoid import * - use namespaces.

BTW be sure and set the current precision before importing x from anywhere!

Steve Barnes
  • 24,968
  • 6
  • 54
  • 63
-1

I think the problem is that when you do

 >>> Decimal(426880) * Decimal(x)

It's interpreted by Python as

>>> Decimal(426880) * Decimal(float(x))

When you first declare x, Try to make sure it's declared as a Decimal and not a floating point number. I maybe horribly wrong, but I think you should check your code to try and see if you might have done that.