fork download
  1. #(2^((2^(99-1))-1))*(2-(2^-268435356))
  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 = 999999999999999999999999999999 # 指数上限を増やす
  8. s = ctx.power(2,316912650057057350374175801343)
  9. print(s)
  10. w = ctx.power(2,-268435356)
  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 66588KB
stdin
Standard input is empty
stdout
999999999
6.147648459638741097546783896989532260893094014871590979710119171128753016997258594287886092318257572E+95400213672536764061089706839
8.856471950077022419726879628695432520807436474331664254553334286133124835624004103106283400151968520E-80807095
1.229529691927748219509356779397906452178618802974318195942023834225750603399451718857577218463651514E+95400213672536764061089706840
1.2e+95400213672536764061089706840