fork download
  1. #(2^((2^(w-1))-1))*(2-(2^-t))
  2. #(2^((2^(123-1))-1))*(2-(2^-17179869060))
  3. from decimal import *
  4. getcontext().prec = 100
  5. from decimal import localcontext
  6. with localcontext() as ctx:
  7. print(ctx.Emax) # デフォルトの指数上限は999999なので、今回の計算だと足りない
  8. ctx.Emax = 10**10**5 # 指数上限を増やす
  9. #指数部
  10. w = 123
  11. #仮数部
  12. t = 17179869060
  13. a = ctx.power(2,(w - 1))
  14. b = ctx.power(2,(a - 1))
  15. print(b)
  16. c = t * -1
  17. d = ctx.power(2,c)
  18. print(d)
  19. e = (b * 2 - b * d)
  20. #最大値
  21. print(e)
  22. #必要に応じて有効桁を調整する
  23. format_str = "{:.1e}".format(e)
  24. print(format_str)
  25. f = e.log10()
  26. #桁数-1
  27. print(f)
  28. g = f.log10()
  29. #桁数の桁数-1
  30. print(g)
  31. h = ctx.power(2,t)
  32. i = h.log10()
  33. #有効桁数
  34. print(i)
  35.  
Success #stdin #stdout 0.12s 66800KB
stdin
Standard input is empty
stdout
999999999
4.341605094934883591976110557650570569327746248073443095894868429817972021590682266001087930195328807E+1600549991230302558593939207032863010
0E-1000000098
8.683210189869767183952221115301141138655492496146886191789736859635944043181364532002175860390657614E+1600549991230302558593939207032863010
8.7e+1600549991230302558593939207032863010
1600549991230302558593939207032863010.938680313886406879351789440394201266597220371244195844097986647
36.20426924335138101280988974244250684110113907750565602945234643027593821771178943461731608255852596
5171655908.639564692074332924395914974760577136735946091220744594791958708188309479840137973136046080