fork download
  1. #(2^((2^(w-1))-1))*(2-(2^-t))
  2. #2^128倍精度
  3. #(2^((2^(519-1))-1))*(2-(2^-10889035741470030830827987437816582766072))
  4. from decimal import *
  5. getcontext().prec = 1000
  6. from decimal import localcontext
  7. with localcontext() as ctx:
  8. print(ctx.Emax) # デフォルトの指数上限は999999なので、今回の計算だと足りない
  9. ctx.Emax = 10**10**5 # 指数上限を増やす
  10. #指数部
  11. w = 519
  12. #仮数部
  13. t = 10889035741470030830827987437816582766072
  14. a = ctx.power(2,(w - 1))
  15. b = ctx.power(2,(a - 1))
  16. print(b)
  17. c = t * -1
  18. d = ctx.power(2,c)
  19. print(d)
  20. e = (b * 2 - b * d)
  21. #最大値
  22. print("最大値")
  23. print(e)
  24. #必要に応じて有効桁を調整する
  25. format_str = "{:.1e}".format(e)
  26. print(format_str)
  27. f = e.log10()
  28. h = ctx.power(2,t)
  29. i = h.log10()
  30. #有効桁数
  31. print("有効桁数")
  32. print(i.quantize(Decimal('0'), rounding=ROUND_FLOOR))
  33.  
Success #stdin #stdout 0.22s 67360KB
stdin
Standard input is empty
stdout
999999999
4.346853863932129765019629442385080522031922903295348848411098379025505160753542182369237092696858024571714134796332208149753492910803510112225878692040886368347042592976630738046128474792766896191032699127683061673472816227682557248193998406381702535273771818121471791254675847982074440769914639049388465380104256020120729565525428767454593483679666840345438047848287196489201388491121455238444361254436826312983215714599659709581200239694835401125265063848595850842899523228670049458019937072733592397444083837582191505965176368768924308585623865418558155645328728011009423807581777694288670194386992928912925974034500495152235956704462996382286528521841111987796468671436954458062475235723242782867984226664645014754046347387225173809448349130114852806247469088166282382820718720841005645789862149097105458322975838002674861899376822007939055591261532387755243029235347014942234512271300949357615364449185893666457960394812643641555530164688738814346313190535063795287128216580906099942080328973954E+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343470463409842392677007886631633129570799399839688363235723
0E-1000000998
最大値
8.693707727864259530039258884770161044063845806590697696822196758051010321507084364738474185393716049143428269592664416299506985821607020224451757384081772736694085185953261476092256949585533792382065398255366123346945632455365114496387996812763405070547543636242943582509351695964148881539829278098776930760208512040241459131050857534909186967359333680690876095696574392978402776982242910476888722508873652625966431429199319419162400479389670802250530127697191701685799046457340098916039874145467184794888167675164383011930352737537848617171247730837116311290657456022018847615163555388577340388773985857825851948069000990304471913408925992764573057043682223975592937342873908916124950471446485565735968453329290029508092694774450347618896698260229705612494938176332564765641437441682011291579724298194210916645951676005349723798753644015878111182523064775510486058470694029884469024542601898715230728898371787332915920789625287283111060329377477628692626381070127590574256433161812199884160657947908E+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343470463409842392677007886631633129570799399839688363235723
8.7e+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343470463409842392677007886631633129570799399839688363235723
有効桁数
3277926382039659640000387496003303446245