factorials मिल बड़े असली तेजी से:
>>> math.factorial(170)
7257415615307998967396728211129263114716991681296451376543577798900561843401706157852350749242617459511490991237838520776666022565442753025328900773207510902400430280058295603966612599658257104398558294257568966313439612262571094946806711205568880457193340212661452800000000000000000000000000000000000000000L
नोट L
; 170 के भाज्य अभी भी एक नाव को convertable है:
>>> float(math.factorial(170))
7.257415615307999e+306
लेकिन अगले भाज्य बहुत बड़ी है:
>>> float(math.factorial(171))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to float
आप decimal
module इस्तेमाल कर सकते हैं; गणना धीमी हो जाएगी, लेकिन Decimal()
वर्ग factorials इस आकार संभाल कर सकते हैं:
>>> from decimal import Decimal
>>> Decimal(math.factorial(171))
Decimal('1241018070217667823424840524103103992616605577501693185388951803611996075221691752992751978120487585576464959501670387052809889858690710767331242032218484364310473577889968548278290754541561964852153468318044293239598173696899657235903947616152278558180061176365108428800000000000000000000000000000000000000000')
आप भर Decimal()
मूल्यों का उपयोग करना होगा:
from decimal import *
with localcontext() as ctx:
ctx.prec = 32 # desired precision
p = ctx.power(3, idx)
depart = ctx.exp(-3) * p
depart /= math.factorial(idx)
स्रोत
2013-04-23 16:29:25
क्रमगुणित हो जाता है * वास्तव में * बड़े, * वास्तव में * तेज –
क्या है IDX का मूल्य जब आपको यह त्रुटि मारा? – Pyrce
जब आप एक भाज्य की गणना करना चाहते हैं, की गणना यह लघुगणक है बजाय – zehelvion