fork download
  1. #(2^((2^(43-1))-1))*(2-(2^-16340))
  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 = 9999999999999 # 指数上限を増やす
  8. s = ctx.power(2,4398046511103)
  9. print(s)
  10. w = ctx.power(2,-16340)
  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 65996KB
stdin
Standard input is empty
stdout
999999999
2.107237725502860960570895641295842306448182779480225436870145162081812212935996564103854460571598761E+1323943922167
1.478668599853593525400798454864034789126311466857338892008650386733345405825222659998714367645086465E-4919
4.214475451005721921141791282591684612896365558960450873740290324163624425871993128207708921143197522E+1323943922167
4.2e+1323943922167