It was my understanding that python could handle integers of arbitrary length.
It handles addition and multiplication very well, but seems to fall apart with division.
>>> from decimal import Decimal, getcontext
>>> getcontext().prec=2**5
>>> ORIG_NUM=476939688738611836995535477357070857939902076027788232031989775824606225595773435668861833
>>> print(Decimal(ORIG_NUM)/7)
6.8134241248373119570790782479582E+88
>>> print("%.6f" % (Decimal(ORIG_NUM)/7))
68134241248373123068520468160885027682039120236463560535175757714209021725053511199096832.000000
I do not want the e notation hence the getcontext().prec attempts. Also, confused by the %f dropping the decimal?
>>> getcontext().prec=2**7
>>>QUOTIENT= (Decimal(476939688738611836995535477357070857939902076027788232031989775824606225595773435668861833)/7)
>>>print(QUOTIENT)
68134241248373119570790782479581551134271725146826890290284253689229460799396205095551690.428571428571428571428571428571428571429
>>>QUOTIENT*7
4.7693968873861185e+89
>>> Decimal(QUOTIENT)*7
Decimal('476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824')
>>> print(Decimal(QUOTIENT)*7)
476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824
>>> print(Decimal(QUOTIENT)*7)==ORIG_NUM
476939688738611861479643277126195193774273841655244923746230303999463152075374578393677824
False
Second issue is the numbers do not match up.
Any information on the subject?
Hope that’s better…
print(Decimal(QUOTIENT)*7)==ORIG_NUMfails because theprintfunction returnsNone.If you want exact division, use the
Fractionclass.