Panic at the Exponents!

Stu and I have been promoting our new book over at the JavaRanch all week, and the conversations have been fun. There's one guy over there who seems to have gone from an interested seeker to a Java-defender over the course of the week (even though we are saying, repeatedly, that Java isn't BAD, just that Ruby and Rails are different, with good things to offer). Regardless, he posted this handy little bit:

  try
  2**2**2**2**2
  on Ruby 15 minutes.

He'd made the point earlier in another thread, as well, that it took 15 minutes to compute this in Ruby.

Now, I'm probably just a total idiot, but I looked at that and said "How in the world did it take 15 minutes to compute 2 to the fifth power? What kind of computer is he using, a Commodore Vic20?"

So I fired up irb on my MacBook pro and typed in:

  2**2**2**2**2

and in about a quarter of a second, I got back the answer. I was surprised both by how quick it was, and by the answer I got, which was:

20035299304068464649790723515602557504478254755697514192650169737108940595563114530895061308809333481010382343429072631818229493821188126688695063647615470291650418719163515879663472194429309279820843091048559905701593189596395248633723672030029169695921561087649488892540908059114570376752085002066715637023661263597471448071117748158809141357427209671901518362825606180914588526998261414250301233911082736038437678764490432059603791244909057075603140350761625624760318637931264847037437829549756137 70981604614413308692118102485959152380195331030292162800160568670105651646750568038741529463842244845292537361442533614373729088303794601274724958414864915930647252015155693922628180691650796381064132275307267143998158508811292628901134237782705567421080070065283963322155077831214288551675554073345107213112427399562982719769150054883905223804357045848197956393157853510018992000024141963706813559840464039472194016069517690156119726982337890017641517190051133466306898140219383481435426387306539552 96969138802415816185956110064036211979610185953480278716720012260464249238511139340046435162386756707874525946467090388654774348321789701276445552940909202195958575162297333357615955239488529757995402847194352991354376370598692891375715374000198639433246489005254310662966916524341917469138963247656028941519977547770313806478134230959619096065459130089018888758808473362595606544488850144733570605881709016210849971452956834406197969056546981363116205357936979140323632849623304642106613620022017578 78518574091620504897117818204001872829399434461862243280098373237649318147898481194527130074402207656809103762039992034920239066262644919091679854615157788390603977207592793788522412943010174580868622633692847258514030396155585643303854506886522131148136384083847782637904596071868767285097634712719888906804782432303947186505256609781507298611414303058169279249714091610594171853522758875044775922183011587807019755357222414000195481020056617735897814995323252085897534635470077866904064290167638081 61740550405117670093673202804549339027992491867306539931640720492238474815280619166900933805732120816350707634351669869625020969023162859350071874190579161241536897514808261904847946571736601005892476655445840838334790544144817684255327207315586349347605137419779525190365032198020108764738368682531025183377533908861426184800374008082238104076468878471647552945326947661700424461063311238021134588694532200116564076327023074292426051582811070387018345324567635625951430032037432740780879056283663406 96503084422585596703927186946115851379338647569974856867007982396060439347885086164926030494506174341236582835214480672667684180708375486221140823657980296120002744132443843240233125740354501935242877643088023285085588608996277445816468085787511580701474376386797695504999164399828435729041537814343884730348426190338884149403136613985425763557710533558020662218557706008255128889333222643628198483861323957067619140963853383237434375883085923372228464428799624560547693242899843265267737837317328806 32107532112386806046747084280511664887090847702912081611049125555983223662448685566514026846412096949825905655192161881043412268389962830716548685255369148502995396755039549383718534059000961874894739928804324963731657538036735867101757839948184717984982469480605320819960661834340124760966395197780214411997525467040806084993441782562850927265237098986515394621930046073645079262129759176982938923670151709920915315678144397912484757062378046000099182933213068805700465914583872080880168874458355579 26258465124763087148566313528934166117490617526671492672176128330845273936469244582892571388877839056300482483799839692029222215486145902373478222682521639957440801727144146179559226175083889020074169926238300282286249284182671243405751424188569994272331606998712986882771820617214453142574944015066139463169197629181506579745526236191224848063890033669074365989226349564114665503062965960199720636202603521917776740668777463549375318899587866282125469797102065747232721372918144666659421872003474508 94283091153518927111428710837615922238027660532782335166155514936937577846667014571797190122711781278045024002638475878833939681796295069079881712169068692953824852983002347606845411417813911064856023654975422749723100761513187002405391051091381784372179142252858743209852495787803468370333781842144401713868812424998441861812927119853331538256732187042153063119774853521467095533462633661086466733229240987984925669110951614361860154890974024191350962304361219612816595051866602203071561368473236466 08689050142639139065150639081993788523183650598972991254044794434251667742996598118492331515552728832740283526884424087528112832899806259126736995462473415433335001472314306127503903073971352520693381738433229507010490618675394331307847980156551303847581556852362180104196502555961819349863159132330360964619059902361126811960234418433633345949276319461017166529138237171823942992162725384617760656945422978770713831988170369645886898118632109769003557358846244648357062914530527571012788720279653644 79724025405448132748391794128826423835171949197209797145936887537198729130831738033911016128547415377377715951728084111627597186384924222802373441925469991983672192131287035585307966942713416391033882754318613643490100943197409047331014476299861725424423355612237435715825933382804986243892498222780715951762757847109475119033482241412025182688713728193104253478196128440176479531505057110722974314569915223451643121848657575786528197564843508958384722923534559464521215831657751471298708225909292655 63883665112068194383690411625266871004456024370420066370900194118555716047204464369693285006004692814050711906926139399390273553454556747031490388602202463994826050176243196930564066636662609020704888743889890749815286544438186291738290105182086993638266186830391527326458128678280660133750009659336462514609172318031293034787742123467911845479131110989779464821692250562939995679348380169915743970053754213448587458685604728675106542334189383909911058646559511364606105515683854121745980180713316361 25730796111683438637676673073545834947897883163301292408008363568259391571131309780305164417166825183465736759341980849589479409832925000863897785634946932124734261030627137450772861569225966285738579055332406418490184513282846327092697538308673084091422476594744399733481308109863994173797896570106870267341619671965915995885378348229882701256058423655895396903064749655841479813109971575420432563957760704851008815782914082507777385597901291294073094627859445058594122731948127532251523248015034665 19048228961406646890305102510916237770448486230229488966711380555607956620732449373374027836767300203011615227008921843515652121379215748206859356920790214502277133099987729459596952817044582181956080965811702798062669891205061560742325686842271306295009864421853470810407128917646906550836129916694778023822502789667843489199409657361704586786242554006942516693979292624714524945408858422726153755260071904336329196375777502176005195800693847635789586878489536872122898557806826518192703632099480155 87445557517531273647142129553649408438558661520801211507907506855334448925869328385965301327204697069457154695935365857178889486233329246520273585318853337094845540333656535698817258252891805663548836374379334841184558016833182767683464629199560551347003914787680864032262961664156066750815371064672310846196424753749055374480531822600271021640098058449752602303564003808347205314994117296573678506642140084269649710324191918212121320693976914392336837470922826773870813223668008692470349158684099115 30983154120635661231875043054675369832308279664574176208065931772656858416818379661061449634325441117069417002226578173583512598210807691019610522292638797450490192543119006205619065774524161919131875339840493439768233102984658933183730158095925228292068208622303325852801192664963144413164427730032377922747123306964171499455322610354751456312906688543454268697884477429817774937101176146516241836166802548152963353084908499430067636548061029400946937506098455885580439704859144495844450799784970455 83550685408745163316464118083123079704389849190506587586425810738422420591191941674182490452700288263983057950057341711487031187142834184499153456702915280104485145176055306971441761368582384102787659324662689978418319620312262421177391477208004883578333569204533935953254564897028558589735505751235129536540502842081022785248776603574246366673148680279486052445782673626230852978265057114624846595914210278122788941448163994973881884622768244851622051817076722169863265701654316919742651230041757329 90447353767253684579275436541282655358185804684006936771860502007054724754840080553042495185449526724726134731817474218007857469346544713603697588411802940803961674694628854067917213860122541950381970453841726800639882065632879283958270851091995883944829777564715202613287108952616341770715164289948795356485455355314875497813400996485449863582484769059003311696130376612792346432312970662841130742704620203201336835038542536031363676357521260470742531120923340283748294945310472741896928727557202761 52722682833767413934256526532830684699975970977500055608899326850250492128840682741398816315404564903507758716800740556857240217586854390532281337707074158307562696283169556874240605277264858530506113563848519659189686495963355682169754376214307786659347304501648224329648912707098980766766256715172690620588155496663825738292741820822789606844882229833948166709840390242835143068137672534601260072692629694686727507943461904399966189796119287505194423564026443032717373415912814960561683539881885694 84045342311424613559925272330064881627466723523751234311893442118885085079358163848994487544756331689213869675574302737953785262542329024881047181939037220666894702204258836895840939998453560948869946833852579675161882159410981624918741813364726965123980677561947912557957446471427868624053750576104204267149366084980238274680575982591331006919941904651906531171908926077949119217946407355129633864523035673345588033313197080365457184791550432654899559705862888286866606618021882248602144999973122164 13817065348017551043840662441282280361664890425737764095632648282525840766904560843949032529052633753231650908768133661424239830953080654966187938194912003391948949406513239881664208008839555494223709673484007264270570116508907519615537018626479745638118785617545711340047381076276301495330973517418065547911266093803431137853253288353335202493436597912934128485497094682632907583019307266533778255931433111096384805394085928398890779621047984791968687653998747709591278872747587443980677982496827827 22009264499445593804146087706419418104407582698056880389496546165879839046605876453418102899071942930217745199761044950431968415034555140448209289333786573630528306199900777487269229986082790531716918765788609089418170579934048902184415597910926768627965975839524839267348836347456516870161662406424242412289611180106156823425393921800524834547237792199112285959141918774917938233400100781283265067102817813960291209147201009478787525512633728842223538694900679276645116347581011938753196572421214760 38284774774571704578610417385747911301908583877890152334343013005282797038580359815182929600305682612091950943737325454171056383887047528950563961029843641360935641632589408137981511693338619797339821670761004607980096016024823096943043806956620123213650140549586250615282588033022908385812478469315720323233601899469437647726721879376826431828382603564520699468630216048874528424363593558622333506235945002890558581611275341783750455936126130852640828051213873177490200249552738734585956405160830583 05377073253397155262044470542957353836111367752316997274029294167420442324811387507563131907827218886405337469421384216992886294047963530515056078812636620649723125757901959887304119562622734372890051656111109411174527796548279047125058199907749806382155937688554649882293898540829132512907647838632249478101675349169348928810420301561028338614382737816094634133538357834076531432141715065587754782025245478065730134227747061674424196895261316427410469547462148375628829977180418678508454696561915090 86958742511844358373065909514609804512474094113738999278224929833677960110153870961297497055663016373072027507347599229437923938244274211861582361613178863925530951171884212985083072382597291441422515794038830113590833316518582349672212596218125070581137594955250227472746743698871319266707692991990844671612287388584575846227265733307537355728239516169641751986750126817454293237382941438248143771398619067166575729458078048205595118816871880752129718326364421553367877512747669407901170575098195750 84563565217389544179875074523854455200133572033332379895074393905312918212255259833790909463630202185353848854825062897715616963860712382771725621313460549401770413581731931763370136332252819127547191443450920711848838366818174263342949611870091503049165339464763717766439120798347494627397822171502090670190302469762151278521956142070806461631373236517853976292092025500288962012970141379640038055734949269073535145961208674796547733692958773628635660143767964038430796864138563447801328261284589184 89852804804884418082163942397401436290348166545811445436646003249061876303950235640204453074821024136689519664422133920075747912868380517515063466256939193774028351207566626082989049187728783385217852279204577184696585527879044756219266399200840930207567392536373562839082981757790215320210640961737328359849406665214119818381088451545977289516457213189779790749194101314836854463961690460703010759681893374121757598816512700076126278916951040631585763753478742007022205107089125761236165802680681585 84998526314658780866168007332646768302063916972030648944056281954061906852420030534631566218913273090696873531816410945142880366059952202482488867115544291047219291342483464387053685086487490991788126705656653871910497218200423714927401644609434598453925367061322106165330856620211889682340057526754861014769936887382095845522115719234796868881608536316158628801503959494185294892270744108282071693033878180849362040182552222710109856534448172074707560192459155994310729495781978785905789400525401228 67517142511184356437184053563024181225473266093302710397968091064939272722683035410467632591355279683837705019855234621222858410557119921731717969804339317707750755627056047831779844447637560254637033369247114220815519973691371975163241302748712199863404548248524570118553342675264715978310731245663429805221455494156252724028915333354349341217862037007260315279870771872491234494477147909520734761385425485311552773301030342476835865496093722324007154518129732692081058424090557725645803681462234493 18970813889714329983134761779967971245378231070373915147387869211918756670031932128189680332269659445928621060743882741691946516226763254066507088107103039417886056489376981673415902592519461182364294565266937220315550470021359884629275801252771542201662995486313032491231102962792372389976641680349714122652793190763632613681414551637665655983978848938173308266877990196288693229659737995193162118721545528739417024366988559388879331674453336311954151840408828381519342123412282003095031334105070476 01599879854725291906652224793197154403317948368373732208218857733416238564413807005419135302459439135025545318864547962522602517629283743304651023610575835145507394433396102162296754614157811271970017386114942795014112532806212547758105129720884652631580948066336876701473107335407177108766159358568140982129677307591973829734414452566887708553245708889583209938234321027182241147637327913575686154212528496579033350931527769255058456440105521926445053120737562877449981636463328358161403301758139673 59427327690448920361880386754955751806890058532927201493923500525845146706982628548257883267398735220457228239290207144822219885587102896991935873074277815159757620764023951243860202032596596250212578349957710085626386118233813318509014686577064010676278617583772772895892746039403930337271873850536912957126715066896688493880885142943609962012966759079225082275313812849851526902931700263136328942095797577959327635531162066753488651317323872438748063513314512644889967589828812925480076425186586490 24111112730135719718138160258317850693224400799865663537154408845486639318170839573578079905973083909488180406093595919090747396090441015051632174968141210076571917748376735575100073361692238653742907945780320004233745280756615304292901449578062963413838355178359976470885134900485697369796523869584599459559209070905895689145114141268450546211794502661175016692826025095077077821195043261738322356243760177679936279609936897519139496503335850715541843645685261667424368892037103749532842592713161053 78349807407391586338179676584252580367372064693512486522384813416638080615057048290598906964519364400185971204257230073164100099169875242603773621777634306216167448849308109299010095179745415642512048220867145868492551324442667771278637282113315362243010918243912433802140462422233491535595168908162884879899882736304453724321742802157557779670216663170479697281724833928410156422745072717792693999297403080727703950135815451424940490265361058254093731146531049433824843797186069372144446008267980024 71229489405761853892203425608302697052876621377373594394224114707074072902725461307358541745691419446487624357682397065703184168467540733466346293673983620004041400714054277632480132742202685393698869787607009590048684650626771363070979821006557285101306601010780633743344773073478653881742681230743766066643312775356466578603715192922768440458273283243808212841218776132042460464900801054731426749260826922155637405486241717031027919996942645620955619816454547662045022411449404749349832206807191352 76798674781345820385957041346617793722853494003163159954409368408957253343870298671782977037333280680176463950209002394193149911500910527682111951099906316615031158558283558260717941005252858361136996130344279017381178741206128818206202326384986151565645123004779296756361834576810504334176954306753804111392855379252924134733948105053202570872818630729115891133594201476187266429156403637192760230628384065042544174233546454998705531872688792642410214736369862546374715974435494344389973005174252511 08773578863909468120966734281525859199248576404880550713298142993599114632399191139599267525763590074465728101918058418073422277347213977232182317717169164001088261125490933611867805757223910181861685491085008852722743742120865248523724562486976622453848192986711294529455154970305859193071984971054141816369689761311267440270096486675459345670599369954645005589216280479763656861333165639073957032720343891754152675009150111988568727088481955316769316812728921430313768180164454773675183534978579242 76463354162433601125960252109501612264110346083465648235597934274056868849224458745493776752120324703803035491157544831295275891939893680876327685438769557694881422844311998595700727521393176837831770339130423060958999137314684569010422095161967070506420256733873446115655276175992727151877660010238944760539789516945708802728736225121076224091810066700883474737605156285533943565843756271241244457651663064085939507947550920463932245202535463634444791755661725962187199279186575490857852950012840229 03506151493731010700944615101161371242376142672254173205595920278212932572594714641722497732131638184532655527960427054187149623658525245864893325414506264233788565146467060429856478196846159366328895429978072254226479040061601975197500746054515006029180663827149701611098795133663377137843441619405312144529185518013657555866761501937302969193207612000925506508158327550849934076879725236998702356793102680413674571895664143185267905471716996299036301554564509004480278905570196832831363071899769915 3166679208958768572290600915472919636381673596673959975710326015571920237348580521128117458610065152598883843114511894880552129145775699146577530041384717124577965048175856395072895337539755822087777506072339445587895905719156736

At this point, I realized two things. One, the guy was either running some decrepit computer (or was using Why's hobix in-browser interpreter, which CAN NOT BE a reasonable measure of anything), and two, that I didn't understand how the exponent operator worked in Ruby.

I just assumed that 2**2**2**2**2 would be "two to the fifth", which is 32. Then I looked at it longer and said, no, that can't be right, it must be 65536, or "two squared, then squared again, then squared again, then squared again". But when I got that answer, I realized that the exponents are evaluated right to left, and so what you actually get is "2 to the (2 to the (2 to the (2 to the 2))))" which is "2 to the 65536" which is a darn big number.

Is anybody else surprised by this, or am I just dumb?