fork download
  1. #(2^((2^(79-1))-1))*(2-(2^-8388528))
  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 = 999999999999999999999999 # 指数上限を増やす
  8. s = ctx.power(2,302231454903657293676543)
  9. print(s)
  10. w = ctx.power(2,-8388528)
  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.07s 66664KB
stdin
Standard input is empty
stdout
999999999
7.374883855202493988771765124623136801606767984119367004430593304336145981511695904136853481178482372E+90980733559166683255280
2.834867827105819133080193349941224685164529248153257062592092468822860398274544284555615058948576891E-2525199
1.474976771040498797754353024924627360321353596823873400886118660867229196302339180827370696235696474E+90980733559166683255281
1.5e+90980733559166683255281