fork download
  1. #(2^((2^(39-1))-1))*(2-(2^-8152))
  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 = 999999999999 # 指数上限を増やす
  8. s = ctx.power(2,274877906943)
  9. print(s)
  10. w = ctx.power(2,-8152)
  11. print(w)
  12. t = (s * 2 - s * w)
  13. print(t)
  14. #必要に応じて有効桁を調整する
  15. format_str = "{:.1e}".format(t)
  16. print(format_str)
  17.  
Success #stdin #stdout 0.06s 66284KB
stdin
Standard input is empty
stdout
999999999
1.498016078871939234614782806514780630005443800584932485268520204797475351278329033110381059201558261E+82746495135
1.008034386555799560015649502870702802456208398723202940613888793744689823278739791887193592485781738E-2454
2.996032157743878469229565613029561260010887601169864970537040409594950702556658066220762118403116522E+82746495135
3.0e+82746495135