fork download
  1. #(2^((2^(111-1))-1))*(2-(2^-2147483536))
  2. from decimal import *
  3. getcontext().prec = 100
  4. from decimal import localcontext
  5. with localcontext() as ctx:
  6. print(ctx.Emax) # デフォルトの指数上限は999999なので、今回の計算だと足りない
  7. ctx.Emax = 9999999999999999999999999999999999 # 指数上限を増やす
  8. s = ctx.power(2,1298074214633706907132624082305023)
  9. print(s)
  10. w = ctx.power(2,-2147483536)
  11. print(w)
  12. t = (s * 2 - s * w)
  13. print(t)
  14. #必要に応じて有効桁を調整する
  15. format_str = "{:.1e}".format(t)
  16. print(format_str)
Success #stdin #stdout 0.06s 66460KB
stdin
Standard input is empty
stdout
999999999
1.862086946226466351923789296326870750335271608507516490601873430291967228184196405248068975532054568E+390759275202710585594223439217007
2.947467296277920237262607740899543479217201874070624922566888686444986780781121943740414997973171254E-646456960
3.724173892452932703847578592653741500670543217015032981203746860583934456368392810496137951064109136E+390759275202710585594223439217007
3.7e+390759275202710585594223439217007