fork download
  1. #(2^((2^(w-1))-1))*(2-(2^-t))
  2. #2^256倍精度
  3. #(2^((2^(1031-1))-1))*(2-(2^-3705346855594118253554271520278013051304639509300498049262642688253220148476920))
  4. from decimal import *
  5. getcontext().prec = 1000
  6. from decimal import localcontext
  7. with localcontext() as ctx:
  8. print(ctx.Emax) # デフォルトの指数上限は999999なので、今回の計算だと足りない
  9. ctx.Emax = 10**10**5 # 指数上限を増やす
  10. #指数部
  11. w = 1031
  12. #仮数部
  13. t = 3705346855594118253554271520278013051304639509300498049262642688253220148476920
  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. h = ctx.power(2,t)
  29. i = h.log10()
  30. #有効桁数
  31. print("有効桁数")
  32. print(i.quantize(Decimal('0'), rounding=ROUND_FLOOR))
  33.  
  34.  
Success #stdin #stdout 0.26s 68104KB
stdin
Standard input is empty
stdout
999999999
4.955242998025921008059873750368479228154515652982804129805113860030882630013658532081681787079333246185560410191525595386492068808290469983825231613080426852996394421002229136689775221129180912684012357377870445326587606509750750972474183019715000274215421450082726128584644273293105912858398007612908621952532657444937151325876628248184322645102126258819821345052745541287097135342645192848057565904003252141602129566168854376785369371522922011763137766103306845060494650603656301026435436043023926113563349026737323275682057081324171704763049012351478867074128998469897118598252736214027863023198773716679718380937139754467639989494415688131658905331028131372363619667750665737475922665620609249902826995888942132452015274973485396699751996436215371897629918018601584569346258090835152188683964231013357473919832606341873421152102192095871342626452926078958405438612360623086261524862921160232861577737959500811940997893169467244577526466229566995341302170699942039219898770884363727902068398877714E+3463421162193739006115755670512565398970613387487447565514569146688895581002774845198486130174991073425006674893629825010745682438297357167106359363123129372954553007564899435132085154888968620512342729245054138016101973375947982144386962745355867469433717483800062667561597573362502266464406927622369746982231
0E-1000000998
最大値
9.910485996051842016119747500736958456309031305965608259610227720061765260027317064163363574158666492371120820383051190772984137616580939967650463226160853705992788842004458273379550442258361825368024714755740890653175213019501501944948366039430000548430842900165452257169288546586211825716796015225817243905065314889874302651753256496368645290204252517639642690105491082574194270685290385696115131808006504283204259132337708753570738743045844023526275532206613690120989301207312602052870872086047852227126698053474646551364114162648343409526098024702957734148257996939794237196505472428055726046397547433359436761874279508935279978988831376263317810662056262744727239335501331474951845331241218499805653991777884264904030549946970793399503992872430743795259836037203169138692516181670304377367928462026714947839665212683746842304204384191742685252905852157916810877224721246172523049725842320465723155475919001623881995786338934489155052932459133990682604341399884078439797541768727455804136797755428E+3463421162193739006115755670512565398970613387487447565514569146688895581002774845198486130174991073425006674893629825010745682438297357167106359363123129372954553007564899435132085154888968620512342729245054138016101973375947982144386962745355867469433717483800062667561597573362502266464406927622369746982231
9.9e+3463421162193739006115755670512565398970613387487447565514569146688895581002774845198486130174991073425006674893629825010745682438297357167106359363123129372954553007564899435132085154888968620512342729245054138016101973375947982144386962745355867469433717483800062667561597573362502266464406927622369746982231
有効桁数
1115420547873043773755702902429773375888111499806515058737419091082898588449659