我需要一个包含 1000 个十进制数字的类来计算一系列中的 pi 数。花时间并不重要。我如何定义__add__
& ... 函数来做到这一点?For example I need a value can hold this number: 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113
:))
这个数字使用decimal.Decimal
显示如下:
from decimal import Decimal as dc
>>> x=dc(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113)
>>> x
Decimal('3.141592653589793115997963468544185161590576171875')
但是我需要一个包含所有数字的新类,我可以在其中使用加法、除法和...函数,例如 2+1,pi 数就是一个例子,我不需要计算我想要计算的 pi 数超大十进制数字!