pow() returns Infinity?

Hi

I'm trying to evaluate 2^19937 with the pow function.

In this case I'm using the following code:

1
2
3
double b = 2;
double n = 19937;
double res = pow(b, n);


However res is evaluated as 1.#INF000000000000, what am I missing here?

Many thanks
2^19937 is a pretty massive number... maybe TOO long to store in a var, try this...

std::cout << pow(b, n);
2^19937 is a GIANT number...over 6000 digits.

There's no way you could possibly fit that in any of the fundamental data types.

In fact, it's (sorry for wall of numbers)
43154247973881626480552355163379198390539350432267115051652505414033306801376580
91130451362931858466554526993825764883531790221733458441390952826915460916801900
78753437413962968019201144864809026614143184432769803000667281049840954515881760
77132969843762134621790396391341285205627619600513106646376648615994236675486537
48024196435029593516866236390904794834769231397830137782078571241905447433284452
91831729732423108882650813216264694510777078122828294447750226804880578200287646
59399164766265200900561495800344054353690389862894061792872011120833614808447482
91354732836727787956564830784690911694586623016970240126024018702874665003344577
45703154312929960251877807901193759028631710841496424733789862675033089613749057
66340905289572290016038000571630875191373979555047468154333253474991046248132504
51634179655147057548145920085947261483621387555711686444578975088627799648730430
84504842234206292665185560243393391908443689210184248446770427276646018529149252
77280922697538426770257333928954401205465895610347658855386633902546289962132643
28242574803578623358060815469654693256383332767076989943977488852668727852745100
29630591469638757154257355344759797344631006783673933274021499309687782967413915
14599602374213629898720611431410402147238998090962818915890645693934483330994169
63229587799584899336674701487176349480554999616305154122540346529700772114623135
57040814930986630657336771911728539870957481678162560842128233801686253345864312
54034670806135273543270714478876861861983320777280644806691125713197262581763151
31359642954776357636783701934983517846214429496075719091805462511414366638418943
38525764522893476524546315357404687862289458856546085620580424689873724369214450
92315377698407168198376538237748614196207041548106379365123192817999006621766467
16711347163271548179587700538269439340040306170045769113534918787488892342934934
01451705717161811257958888892774954269771499145496239163940148229850253316515114
31278802009056808456506818877266609831636883884905621822262933986548645669080672
19170474040889134983568566242806323119852043682632941529075297279834342944650999
22063687813671540917026557727273913294242775293490826005858847665231509574170778
31910016168475685658673192860882070179760307269849987354836042371734660257694347
23550630174411887414129243895814154910060975221688223088761143199647233084238013
71109274494835578150375868496445857499177728699267442183696211376751010832785437
94081749094091043084096774144708436324279476892056200427227961638669149805489831
12124467639993195537148401288636074870647956866904857478285521705474011394592962
21775025755658110674522014489819919686359653615516812739827407601388996388203187
76303668762730157584640042798880691862640268612686180883874939573818125022279689
93026744625577395954246983163786300017127922715140603412990218157065965053260077
58236773981821290873944498591827499990072235924233345678506711865688391867477049
60016277540625331440619019129983789914712515365200336057993508601678807687568562
37785709525554130490292719222018417250235712444991187021064269456506138491937347
43245039662677990384023867816868099620158790905865494235046991907435195510437225
44515740967829084336025938225780730880273855261551972044075620326780624448803490
99823216123168779471561340579324954550952805251801012308725877897411581704824558
89714385967544080813134383755029887267395233752966416155014060916079832292398272
40614783252892479716519936989519187808681221191641747710902480633491091704827441
22828118663244590714578713835123484226138007462191400481815238666604313334487506
79035828382835626880832365754820684796395463838195321745225026823724413632757658
75609119783653298312066708217149316773564340379289724393986744139891855416612295
73935666861265827123469643837712283899804019973907806144367541567107846340467370
24037776534781733670848447347020568666361581380036922533822099094664695919301616
26097920508742175670306505139542860750806159835357541032147095084278461056701367
73979493202420299870773101769258204621070221251412042932253043178961626704777611
51235979354041470848709854654265027720573009003338479053342506041195030300017040
02887892941404603345869926367501355094942750552591581639980523190679610784993580
89668329929768126244231400865703342186809455174050644882903920731671130769513189
22965935090186230948105575195603052407871638092191644337545148633010009159169858
56242176563624771328981678548246297376249530251360363412768366456175077031977457
53491280643317653999599434330811847014715871281614939442127661422826290995005574
69810532066100015602957846566161932522694120268311595089496715138451958832171479
82748879261851417819979034417285598607727220866677680426090308754823803345446566
30561924130837445275466814301548771087772801108600432589226225941396828528349704
55710627577014217615652627251534074076254051499319894944591064146605343053785767
09862520049864880961144869258603473714363659194013962706366851389299692869491805
17255681850829882495495481579606316951765874142015979875427342802672345248126356
91573072131537397810416276537150785985041547972876631229467113481585294188164328
25044466692781137474494898385064375787507376496345148625306383391555145690087891
95531599446294449323524881759990711913575593338212170619147718505493663221115722
29203311485024875633031180188056850735698415805181187107786539535712960143729408
65270407021924383167290323231567912289419486240594039074452321678019381871219092
15546076844457357855951361330424220615135645751393727093900970723782710124585383
76783381610233975868548942306960915402499879074534613119239638529507547580582056
25956600817743007191746812655955021747670922460866747744520875607859062334750627
09832859348006778945616960249439281376349565759984748577355399095755731320080904
08300364464922194099340969487305474943012161656867507357495558823403039898746729
75455060957736921559195480815514035915707129930057027117286252843197413312307617
88679750678426019543676030599034070848146460727895549548774214075357062121719825
21929788697869167346256184301754549038641115854295045699209056367415390309680414
72


What do you need such a big number for?
is someone calculating the mersenne twister period?
yea i am, thank you!

so taking into account practical considerations, how would you calculate the reciprocal (1/(1+2^19937)) if you can't readily store such a massive number in memory?
Last edited on
That number...would be very close to 0.

I don't know how accurate this is, but it could possibly be approximately equal to 2.317 * 10^-6002.

You might want to look into arbitrary precision number libraries. (that's what I used to calculate 2^19937)
Such as: http://gmplib.org/
Last edited on
yea, adding another level of detail, this was all part of building a random variate generator with boost. so the idea of calculating the reciprocal was to convert the mersenne twister generated number to a uniform variate using the existing structure.

it's a bit of a learning experience right now so i've opted to go with the boost variate generator to just get the value out.

thanks all again for your help.
Topic archived. No new replies allowed.