/*REXX program calculates GAMMA using the Taylor series coefficients; ≈80 decimal digits*/ /*The GAMMA function symbol is the Greek capital letter: Γ */ numeric digits 90 /*be able to handle extended precision.*/ parse arg LO HI . /*allow specification of gamma arg/args*/ /* [↓] either show a range or a ··· */ do j=word(LO 1, 1) to word(HI LO 9, 1) /* ··· single gamma value.*/ say 'gamma('j") =" gamma(j) /*compute gamma of J and display value.*/ end /*j*/ /* [↑] default LO is one; HI is nine.*/ exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ gamma: procedure; parse arg x; xm=x-1; sum=0 /*coefficients thanks to: Arne Fransén & Staffan Wrigge.*/ #.1 = 1 /* [↓] #.2 is the Euler-Mascheroni constant. */ #.2 = 0.57721566490153286060651209008240243104215933593992359880576723488486772677766467 #.3 = -0.65587807152025388107701951514539048127976638047858434729236244568387083835372210 #.4 = -0.04200263503409523552900393487542981871139450040110609352206581297618009687597599 #.5 = 0.16653861138229148950170079510210523571778150224717434057046890317899386605647425 #.6 = -0.04219773455554433674820830128918739130165268418982248637691887327545901118558900 #.7 = -0.00962197152787697356211492167234819897536294225211300210513886262731167351446074 #.8 = 0.00721894324666309954239501034044657270990480088023831800109478117362259497415854 #.9 = -0.00116516759185906511211397108401838866680933379538405744340750527562002584816653 #.10 = -0.00021524167411495097281572996305364780647824192337833875035026748908563946371678 #.11 = 0.00012805028238811618615319862632816432339489209969367721490054583804120355204347 #.12 = -0.00002013485478078823865568939142102181838229483329797911526116267090822918618897 #.13 = -0.00000125049348214267065734535947383309224232265562115395981534992315749121245561 #.14 = 0.00000113302723198169588237412962033074494332400483862107565429550539546040842730 #.15 = -0.00000020563384169776071034501541300205728365125790262933794534683172533245680371 #.16 = 0.00000000611609510448141581786249868285534286727586571971232086732402927723507435 #.17 = 0.00000000500200764446922293005566504805999130304461274249448171895337887737472132 #.18 = -0.00000000118127457048702014458812656543650557773875950493258759096189263169643391 #.19 = 0.00000000010434267116911005104915403323122501914007098231258121210871073927347588 #.20 = 0.00000000000778226343990507125404993731136077722606808618139293881943550732692987 #.21 = -0.00000000000369680561864220570818781587808576623657096345136099513648454655443000 #.22 = 0.00000000000051003702874544759790154813228632318027268860697076321173501048565735 #.23 = -0.00000000000002058326053566506783222429544855237419746091080810147188058196444349 #.24 = -0.00000000000000534812253942301798237001731872793994898971547812068211168095493211 #.25 = 0.00000000000000122677862823826079015889384662242242816545575045632136601135999606 #.26 = -0.00000000000000011812593016974587695137645868422978312115572918048478798375081233 #.27 = 0.00000000000000000118669225475160033257977724292867407108849407966482711074006109 #.28 = 0.00000000000000000141238065531803178155580394756670903708635075033452562564122263 #.29 = -0.00000000000000000022987456844353702065924785806336992602845059314190367014889830 #.30 = 0.00000000000000000001714406321927337433383963370267257066812656062517433174649858 #.31 = 0.00000000000000000000013373517304936931148647813951222680228750594717618947898583 #.32 = -0.00000000000000000000020542335517666727893250253513557337960820379352387364127301 #.33 = 0.00000000000000000000002736030048607999844831509904330982014865311695836363370165 #.34 = -0.00000000000000000000000173235644591051663905742845156477979906974910879499841377 #.35 = -0.00000000000000000000000002360619024499287287343450735427531007926413552145370486 #.36 = 0.00000000000000000000000001864982941717294430718413161878666898945868429073668232 #.37 = -0.00000000000000000000000000221809562420719720439971691362686037973177950067567580 #.38 = 0.00000000000000000000000000012977819749479936688244144863305941656194998646391332 #.39 = 0.00000000000000000000000000000118069747496652840622274541550997151855968463784158 #.40 = -0.00000000000000000000000000000112458434927708809029365467426143951211941179558301 #.41 = 0.00000000000000000000000000000012770851751408662039902066777511246477487720656005 #.42 = -0.00000000000000000000000000000000739145116961514082346128933010855282371056899245 #.43 = 0.00000000000000000000000000000000001134750257554215760954165259469306393008612196 #.44 = 0.00000000000000000000000000000000004639134641058722029944804907952228463057968680 #.45 = -0.00000000000000000000000000000000000534733681843919887507741819670989332090488591 #.46 = 0.00000000000000000000000000000000000032079959236133526228612372790827943910901464 #.47 = -0.00000000000000000000000000000000000000444582973655075688210159035212464363740144 #.48 = -0.00000000000000000000000000000000000000131117451888198871290105849438992219023663 #.49 = 0.00000000000000000000000000000000000000016470333525438138868182593279063941453996 #.50 = -0.00000000000000000000000000000000000000001056233178503581218600561071538285049997 #.51 = 0.00000000000000000000000000000000000000000026784429826430494783549630718908519485 #.52 = 0.00000000000000000000000000000000000000000002424715494851782689673032938370921241 #=52; do k=# by -1 for # sum=sum*xm + #.k end /*k*/ return 1/sum