fork download
  1. #(2^((2^(w-1))-1))*(2-(2^-t))
  2. #2^128倍精度
  3. #(2^((2^(519-1))-1))*(2-(2^-10889035741470030830827987437816582766072))
  4. from decimal import *
  5. getcontext().prec = 100
  6. from decimal import localcontext
  7. with localcontext() as ctx:
  8. print(ctx.Emax) # デフォルトの指数上限は999999なので、今回の計算だと足りない
  9. ctx.Emax = 10**10**5 # 指数上限を増やす
  10. #指数部
  11. w = 519
  12. #仮数部
  13. t = 10889035741470030830827987437816582766072
  14. a = ctx.power(2,(w - 1))
  15. b = ctx.power(2,(a - 1))
  16. print(b)
  17. c = t * -1
  18. d = ctx.power(2,c)
  19. print(d)
  20. e = (b * 2 - b * d)
  21. #最大値
  22. print("最大値")
  23. print(e)
  24. #必要に応じて有効桁を調整する
  25. format_str = "{:.1e}".format(e)
  26. print(format_str)
  27. f = e.log10()
  28. #桁数-1
  29. # print("桁数-1")
  30. # print(f.quantize(Decimal('0'), rounding=ROUND_FLOOR))
  31. #桁数
  32. # print("桁数")
  33. # print(f.quantize(Decimal('0'), rounding=ROUND_CEILING))
  34. g = f.log10()
  35. #桁数の桁数-1
  36. # print("桁数の桁数-1")
  37. # print(g.quantize(Decimal('0'), rounding=ROUND_FLOOR))
  38. #ウルフラムアルファ確認用
  39. print("ウルフラムアルファ確認用")
  40. print(g)
  41. h = ctx.power(2,t)
  42. i = h.log10()
  43. #有効桁数
  44. print("有効桁数")
  45. print(i.quantize(Decimal('0'), rounding=ROUND_FLOOR))
  46.  
Success #stdin #stdout 0.2s 67252KB
stdin
Standard input is empty
stdout
999999999
4.219242569502619016858102056989071066388391603957714598859821824870625419695946202924755148039116381E+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343478843471144414568958296922314778842870932034756007552127
0E-1000000098
最大値
8.438485139005238033716204113978142132776783207915429197719643649741250839391892405849510296078232762E+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343478843471144414568958296922314778842870932034756007552127
8.4e+258313751232903212140244172706732768962283773495639777019746650509389263410185892774365178070439343478843471144414568958296922314778842870932034756007552127
ウルフラムアルファ確認用
155.4121475262879343174504920533417454413043321365006383883816210366107811703838951914405079213602501
有効桁数
3277926382039659640000387496003303446245