README.txt 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502
  1. /* acoshl.c
  2. *
  3. * Inverse hyperbolic cosine, long double precision
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * long double x, y, acoshl();
  10. *
  11. * y = acoshl( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns inverse hyperbolic cosine of argument.
  18. *
  19. * If 1 <= x < 1.5, a rational approximation
  20. *
  21. * sqrt(2z) * P(z)/Q(z)
  22. *
  23. * where z = x-1, is used. Otherwise,
  24. *
  25. * acosh(x) = log( x + sqrt( (x-1)(x+1) ).
  26. *
  27. *
  28. *
  29. * ACCURACY:
  30. *
  31. * Relative error:
  32. * arithmetic domain # trials peak rms
  33. * IEEE 1,3 30000 2.0e-19 3.9e-20
  34. *
  35. *
  36. * ERROR MESSAGES:
  37. *
  38. * message condition value returned
  39. * acoshl domain |x| < 1 0.0
  40. *
  41. */
  42. /* asinhl.c
  43. *
  44. * Inverse hyperbolic sine, long double precision
  45. *
  46. *
  47. *
  48. * SYNOPSIS:
  49. *
  50. * long double x, y, asinhl();
  51. *
  52. * y = asinhl( x );
  53. *
  54. *
  55. *
  56. * DESCRIPTION:
  57. *
  58. * Returns inverse hyperbolic sine of argument.
  59. *
  60. * If |x| < 0.5, the function is approximated by a rational
  61. * form x + x**3 P(x)/Q(x). Otherwise,
  62. *
  63. * asinh(x) = log( x + sqrt(1 + x*x) ).
  64. *
  65. *
  66. *
  67. * ACCURACY:
  68. *
  69. * Relative error:
  70. * arithmetic domain # trials peak rms
  71. * IEEE -3,3 30000 1.7e-19 3.5e-20
  72. *
  73. */
  74. /* asinl.c
  75. *
  76. * Inverse circular sine, long double precision
  77. *
  78. *
  79. *
  80. * SYNOPSIS:
  81. *
  82. * double x, y, asinl();
  83. *
  84. * y = asinl( x );
  85. *
  86. *
  87. *
  88. * DESCRIPTION:
  89. *
  90. * Returns radian angle between -pi/2 and +pi/2 whose sine is x.
  91. *
  92. * A rational function of the form x + x**3 P(x**2)/Q(x**2)
  93. * is used for |x| in the interval [0, 0.5]. If |x| > 0.5 it is
  94. * transformed by the identity
  95. *
  96. * asin(x) = pi/2 - 2 asin( sqrt( (1-x)/2 ) ).
  97. *
  98. *
  99. * ACCURACY:
  100. *
  101. * Relative error:
  102. * arithmetic domain # trials peak rms
  103. * IEEE -1, 1 30000 2.7e-19 4.8e-20
  104. *
  105. *
  106. * ERROR MESSAGES:
  107. *
  108. * message condition value returned
  109. * asin domain |x| > 1 0.0
  110. *
  111. */
  112. /* acosl()
  113. *
  114. * Inverse circular cosine, long double precision
  115. *
  116. *
  117. *
  118. * SYNOPSIS:
  119. *
  120. * double x, y, acosl();
  121. *
  122. * y = acosl( x );
  123. *
  124. *
  125. *
  126. * DESCRIPTION:
  127. *
  128. * Returns radian angle between -pi/2 and +pi/2 whose cosine
  129. * is x.
  130. *
  131. * Analytically, acos(x) = pi/2 - asin(x). However if |x| is
  132. * near 1, there is cancellation error in subtracting asin(x)
  133. * from pi/2. Hence if x < -0.5,
  134. *
  135. * acos(x) = pi - 2.0 * asin( sqrt((1+x)/2) );
  136. *
  137. * or if x > +0.5,
  138. *
  139. * acos(x) = 2.0 * asin( sqrt((1-x)/2) ).
  140. *
  141. *
  142. * ACCURACY:
  143. *
  144. * Relative error:
  145. * arithmetic domain # trials peak rms
  146. * IEEE -1, 1 30000 1.4e-19 3.5e-20
  147. *
  148. *
  149. * ERROR MESSAGES:
  150. *
  151. * message condition value returned
  152. * asin domain |x| > 1 0.0
  153. */
  154. /* atanhl.c
  155. *
  156. * Inverse hyperbolic tangent, long double precision
  157. *
  158. *
  159. *
  160. * SYNOPSIS:
  161. *
  162. * long double x, y, atanhl();
  163. *
  164. * y = atanhl( x );
  165. *
  166. *
  167. *
  168. * DESCRIPTION:
  169. *
  170. * Returns inverse hyperbolic tangent of argument in the range
  171. * MINLOGL to MAXLOGL.
  172. *
  173. * If |x| < 0.5, the rational form x + x**3 P(x)/Q(x) is
  174. * employed. Otherwise,
  175. * atanh(x) = 0.5 * log( (1+x)/(1-x) ).
  176. *
  177. *
  178. *
  179. * ACCURACY:
  180. *
  181. * Relative error:
  182. * arithmetic domain # trials peak rms
  183. * IEEE -1,1 30000 1.1e-19 3.3e-20
  184. *
  185. */
  186. /* atanl.c
  187. *
  188. * Inverse circular tangent, long double precision
  189. * (arctangent)
  190. *
  191. *
  192. *
  193. * SYNOPSIS:
  194. *
  195. * long double x, y, atanl();
  196. *
  197. * y = atanl( x );
  198. *
  199. *
  200. *
  201. * DESCRIPTION:
  202. *
  203. * Returns radian angle between -pi/2 and +pi/2 whose tangent
  204. * is x.
  205. *
  206. * Range reduction is from four intervals into the interval
  207. * from zero to tan( pi/8 ). The approximant uses a rational
  208. * function of degree 3/4 of the form x + x**3 P(x)/Q(x).
  209. *
  210. *
  211. *
  212. * ACCURACY:
  213. *
  214. * Relative error:
  215. * arithmetic domain # trials peak rms
  216. * IEEE -10, 10 150000 1.3e-19 3.0e-20
  217. *
  218. */
  219. /* atan2l()
  220. *
  221. * Quadrant correct inverse circular tangent,
  222. * long double precision
  223. *
  224. *
  225. *
  226. * SYNOPSIS:
  227. *
  228. * long double x, y, z, atan2l();
  229. *
  230. * z = atan2l( y, x );
  231. *
  232. *
  233. *
  234. * DESCRIPTION:
  235. *
  236. * Returns radian angle whose tangent is y/x.
  237. * Define compile time symbol ANSIC = 1 for ANSI standard,
  238. * range -PI < z <= +PI, args (y,x); else ANSIC = 0 for range
  239. * 0 to 2PI, args (x,y).
  240. *
  241. *
  242. *
  243. * ACCURACY:
  244. *
  245. * Relative error:
  246. * arithmetic domain # trials peak rms
  247. * IEEE -10, 10 60000 1.7e-19 3.2e-20
  248. * See atan.c.
  249. *
  250. */
  251. /* bdtrl.c
  252. *
  253. * Binomial distribution
  254. *
  255. *
  256. *
  257. * SYNOPSIS:
  258. *
  259. * int k, n;
  260. * long double p, y, bdtrl();
  261. *
  262. * y = bdtrl( k, n, p );
  263. *
  264. *
  265. *
  266. * DESCRIPTION:
  267. *
  268. * Returns the sum of the terms 0 through k of the Binomial
  269. * probability density:
  270. *
  271. * k
  272. * -- ( n ) j n-j
  273. * > ( ) p (1-p)
  274. * -- ( j )
  275. * j=0
  276. *
  277. * The terms are not summed directly; instead the incomplete
  278. * beta integral is employed, according to the formula
  279. *
  280. * y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
  281. *
  282. * The arguments must be positive, with p ranging from 0 to 1.
  283. *
  284. *
  285. *
  286. * ACCURACY:
  287. *
  288. * Tested at random points (k,n,p) with a and b between 0
  289. * and 10000 and p between 0 and 1.
  290. * Relative error:
  291. * arithmetic domain # trials peak rms
  292. * IEEE 0,10000 3000 1.6e-14 2.2e-15
  293. *
  294. * ERROR MESSAGES:
  295. *
  296. * message condition value returned
  297. * bdtrl domain k < 0 0.0
  298. * n < k
  299. * x < 0, x > 1
  300. *
  301. */
  302. /* bdtrcl()
  303. *
  304. * Complemented binomial distribution
  305. *
  306. *
  307. *
  308. * SYNOPSIS:
  309. *
  310. * int k, n;
  311. * long double p, y, bdtrcl();
  312. *
  313. * y = bdtrcl( k, n, p );
  314. *
  315. *
  316. *
  317. * DESCRIPTION:
  318. *
  319. * Returns the sum of the terms k+1 through n of the Binomial
  320. * probability density:
  321. *
  322. * n
  323. * -- ( n ) j n-j
  324. * > ( ) p (1-p)
  325. * -- ( j )
  326. * j=k+1
  327. *
  328. * The terms are not summed directly; instead the incomplete
  329. * beta integral is employed, according to the formula
  330. *
  331. * y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
  332. *
  333. * The arguments must be positive, with p ranging from 0 to 1.
  334. *
  335. *
  336. *
  337. * ACCURACY:
  338. *
  339. * See incbet.c.
  340. *
  341. * ERROR MESSAGES:
  342. *
  343. * message condition value returned
  344. * bdtrcl domain x<0, x>1, n<k 0.0
  345. */
  346. /* bdtril()
  347. *
  348. * Inverse binomial distribution
  349. *
  350. *
  351. *
  352. * SYNOPSIS:
  353. *
  354. * int k, n;
  355. * long double p, y, bdtril();
  356. *
  357. * p = bdtril( k, n, y );
  358. *
  359. *
  360. *
  361. * DESCRIPTION:
  362. *
  363. * Finds the event probability p such that the sum of the
  364. * terms 0 through k of the Binomial probability density
  365. * is equal to the given cumulative probability y.
  366. *
  367. * This is accomplished using the inverse beta integral
  368. * function and the relation
  369. *
  370. * 1 - p = incbi( n-k, k+1, y ).
  371. *
  372. * ACCURACY:
  373. *
  374. * See incbi.c.
  375. * Tested at random k, n between 1 and 10000. The "domain" refers to p:
  376. * Relative error:
  377. * arithmetic domain # trials peak rms
  378. * IEEE 0,1 3500 2.0e-15 8.2e-17
  379. *
  380. * ERROR MESSAGES:
  381. *
  382. * message condition value returned
  383. * bdtril domain k < 0, n <= k 0.0
  384. * x < 0, x > 1
  385. */
  386. /* btdtrl.c
  387. *
  388. * Beta distribution
  389. *
  390. *
  391. *
  392. * SYNOPSIS:
  393. *
  394. * long double a, b, x, y, btdtrl();
  395. *
  396. * y = btdtrl( a, b, x );
  397. *
  398. *
  399. *
  400. * DESCRIPTION:
  401. *
  402. * Returns the area from zero to x under the beta density
  403. * function:
  404. *
  405. *
  406. * x
  407. * - -
  408. * | (a+b) | | a-1 b-1
  409. * P(x) = ---------- | t (1-t) dt
  410. * - - | |
  411. * | (a) | (b) -
  412. * 0
  413. *
  414. *
  415. * The mean value of this distribution is a/(a+b). The variance
  416. * is ab/[(a+b)^2 (a+b+1)].
  417. *
  418. * This function is identical to the incomplete beta integral
  419. * function, incbetl(a, b, x).
  420. *
  421. * The complemented function is
  422. *
  423. * 1 - P(1-x) = incbetl( b, a, x );
  424. *
  425. *
  426. * ACCURACY:
  427. *
  428. * See incbetl.c.
  429. *
  430. */
  431. /* cbrtl.c
  432. *
  433. * Cube root, long double precision
  434. *
  435. *
  436. *
  437. * SYNOPSIS:
  438. *
  439. * long double x, y, cbrtl();
  440. *
  441. * y = cbrtl( x );
  442. *
  443. *
  444. *
  445. * DESCRIPTION:
  446. *
  447. * Returns the cube root of the argument, which may be negative.
  448. *
  449. * Range reduction involves determining the power of 2 of
  450. * the argument. A polynomial of degree 2 applied to the
  451. * mantissa, and multiplication by the cube root of 1, 2, or 4
  452. * approximates the root to within about 0.1%. Then Newton's
  453. * iteration is used three times to converge to an accurate
  454. * result.
  455. *
  456. *
  457. *
  458. * ACCURACY:
  459. *
  460. * Relative error:
  461. * arithmetic domain # trials peak rms
  462. * IEEE .125,8 80000 7.0e-20 2.2e-20
  463. * IEEE exp(+-707) 100000 7.0e-20 2.4e-20
  464. *
  465. */
  466. /* chdtrl.c
  467. *
  468. * Chi-square distribution
  469. *
  470. *
  471. *
  472. * SYNOPSIS:
  473. *
  474. * long double df, x, y, chdtrl();
  475. *
  476. * y = chdtrl( df, x );
  477. *
  478. *
  479. *
  480. * DESCRIPTION:
  481. *
  482. * Returns the area under the left hand tail (from 0 to x)
  483. * of the Chi square probability density function with
  484. * v degrees of freedom.
  485. *
  486. *
  487. * inf.
  488. * -
  489. * 1 | | v/2-1 -t/2
  490. * P( x | v ) = ----------- | t e dt
  491. * v/2 - | |
  492. * 2 | (v/2) -
  493. * x
  494. *
  495. * where x is the Chi-square variable.
  496. *
  497. * The incomplete gamma integral is used, according to the
  498. * formula
  499. *
  500. * y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
  501. *
  502. *
  503. * The arguments must both be positive.
  504. *
  505. *
  506. *
  507. * ACCURACY:
  508. *
  509. * See igam().
  510. *
  511. * ERROR MESSAGES:
  512. *
  513. * message condition value returned
  514. * chdtr domain x < 0 or v < 1 0.0
  515. */
  516. /* chdtrcl()
  517. *
  518. * Complemented Chi-square distribution
  519. *
  520. *
  521. *
  522. * SYNOPSIS:
  523. *
  524. * long double v, x, y, chdtrcl();
  525. *
  526. * y = chdtrcl( v, x );
  527. *
  528. *
  529. *
  530. * DESCRIPTION:
  531. *
  532. * Returns the area under the right hand tail (from x to
  533. * infinity) of the Chi square probability density function
  534. * with v degrees of freedom:
  535. *
  536. *
  537. * inf.
  538. * -
  539. * 1 | | v/2-1 -t/2
  540. * P( x | v ) = ----------- | t e dt
  541. * v/2 - | |
  542. * 2 | (v/2) -
  543. * x
  544. *
  545. * where x is the Chi-square variable.
  546. *
  547. * The incomplete gamma integral is used, according to the
  548. * formula
  549. *
  550. * y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
  551. *
  552. *
  553. * The arguments must both be positive.
  554. *
  555. *
  556. *
  557. * ACCURACY:
  558. *
  559. * See igamc().
  560. *
  561. * ERROR MESSAGES:
  562. *
  563. * message condition value returned
  564. * chdtrc domain x < 0 or v < 1 0.0
  565. */
  566. /* chdtril()
  567. *
  568. * Inverse of complemented Chi-square distribution
  569. *
  570. *
  571. *
  572. * SYNOPSIS:
  573. *
  574. * long double df, x, y, chdtril();
  575. *
  576. * x = chdtril( df, y );
  577. *
  578. *
  579. *
  580. *
  581. * DESCRIPTION:
  582. *
  583. * Finds the Chi-square argument x such that the integral
  584. * from x to infinity of the Chi-square density is equal
  585. * to the given cumulative probability y.
  586. *
  587. * This is accomplished using the inverse gamma integral
  588. * function and the relation
  589. *
  590. * x/2 = igami( df/2, y );
  591. *
  592. *
  593. *
  594. *
  595. * ACCURACY:
  596. *
  597. * See igami.c.
  598. *
  599. * ERROR MESSAGES:
  600. *
  601. * message condition value returned
  602. * chdtri domain y < 0 or y > 1 0.0
  603. * v < 1
  604. *
  605. */
  606. /* clogl.c
  607. *
  608. * Complex natural logarithm
  609. *
  610. *
  611. *
  612. * SYNOPSIS:
  613. *
  614. * void clogl();
  615. * cmplxl z, w;
  616. *
  617. * clogl( &z, &w );
  618. *
  619. *
  620. *
  621. * DESCRIPTION:
  622. *
  623. * Returns complex logarithm to the base e (2.718...) of
  624. * the complex argument x.
  625. *
  626. * If z = x + iy, r = sqrt( x**2 + y**2 ),
  627. * then
  628. * w = log(r) + i arctan(y/x).
  629. *
  630. * The arctangent ranges from -PI to +PI.
  631. *
  632. *
  633. * ACCURACY:
  634. *
  635. * Relative error:
  636. * arithmetic domain # trials peak rms
  637. * DEC -10,+10 7000 8.5e-17 1.9e-17
  638. * IEEE -10,+10 30000 5.0e-15 1.1e-16
  639. *
  640. * Larger relative error can be observed for z near 1 +i0.
  641. * In IEEE arithmetic the peak absolute error is 5.2e-16, rms
  642. * absolute error 1.0e-16.
  643. */
  644. /* cexpl()
  645. *
  646. * Complex exponential function
  647. *
  648. *
  649. *
  650. * SYNOPSIS:
  651. *
  652. * void cexpl();
  653. * cmplxl z, w;
  654. *
  655. * cexpl( &z, &w );
  656. *
  657. *
  658. *
  659. * DESCRIPTION:
  660. *
  661. * Returns the exponential of the complex argument z
  662. * into the complex result w.
  663. *
  664. * If
  665. * z = x + iy,
  666. * r = exp(x),
  667. *
  668. * then
  669. *
  670. * w = r cos y + i r sin y.
  671. *
  672. *
  673. * ACCURACY:
  674. *
  675. * Relative error:
  676. * arithmetic domain # trials peak rms
  677. * DEC -10,+10 8700 3.7e-17 1.1e-17
  678. * IEEE -10,+10 30000 3.0e-16 8.7e-17
  679. *
  680. */
  681. /* csinl()
  682. *
  683. * Complex circular sine
  684. *
  685. *
  686. *
  687. * SYNOPSIS:
  688. *
  689. * void csinl();
  690. * cmplxl z, w;
  691. *
  692. * csinl( &z, &w );
  693. *
  694. *
  695. *
  696. * DESCRIPTION:
  697. *
  698. * If
  699. * z = x + iy,
  700. *
  701. * then
  702. *
  703. * w = sin x cosh y + i cos x sinh y.
  704. *
  705. *
  706. *
  707. * ACCURACY:
  708. *
  709. * Relative error:
  710. * arithmetic domain # trials peak rms
  711. * DEC -10,+10 8400 5.3e-17 1.3e-17
  712. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  713. * Also tested by csin(casin(z)) = z.
  714. *
  715. */
  716. /* ccosl()
  717. *
  718. * Complex circular cosine
  719. *
  720. *
  721. *
  722. * SYNOPSIS:
  723. *
  724. * void ccosl();
  725. * cmplxl z, w;
  726. *
  727. * ccosl( &z, &w );
  728. *
  729. *
  730. *
  731. * DESCRIPTION:
  732. *
  733. * If
  734. * z = x + iy,
  735. *
  736. * then
  737. *
  738. * w = cos x cosh y - i sin x sinh y.
  739. *
  740. *
  741. *
  742. * ACCURACY:
  743. *
  744. * Relative error:
  745. * arithmetic domain # trials peak rms
  746. * DEC -10,+10 8400 4.5e-17 1.3e-17
  747. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  748. */
  749. /* ctanl()
  750. *
  751. * Complex circular tangent
  752. *
  753. *
  754. *
  755. * SYNOPSIS:
  756. *
  757. * void ctanl();
  758. * cmplxl z, w;
  759. *
  760. * ctanl( &z, &w );
  761. *
  762. *
  763. *
  764. * DESCRIPTION:
  765. *
  766. * If
  767. * z = x + iy,
  768. *
  769. * then
  770. *
  771. * sin 2x + i sinh 2y
  772. * w = --------------------.
  773. * cos 2x + cosh 2y
  774. *
  775. * On the real axis the denominator is zero at odd multiples
  776. * of PI/2. The denominator is evaluated by its Taylor
  777. * series near these points.
  778. *
  779. *
  780. * ACCURACY:
  781. *
  782. * Relative error:
  783. * arithmetic domain # trials peak rms
  784. * DEC -10,+10 5200 7.1e-17 1.6e-17
  785. * IEEE -10,+10 30000 7.2e-16 1.2e-16
  786. * Also tested by ctan * ccot = 1 and catan(ctan(z)) = z.
  787. */
  788. /* ccotl()
  789. *
  790. * Complex circular cotangent
  791. *
  792. *
  793. *
  794. * SYNOPSIS:
  795. *
  796. * void ccotl();
  797. * cmplxl z, w;
  798. *
  799. * ccotl( &z, &w );
  800. *
  801. *
  802. *
  803. * DESCRIPTION:
  804. *
  805. * If
  806. * z = x + iy,
  807. *
  808. * then
  809. *
  810. * sin 2x - i sinh 2y
  811. * w = --------------------.
  812. * cosh 2y - cos 2x
  813. *
  814. * On the real axis, the denominator has zeros at even
  815. * multiples of PI/2. Near these points it is evaluated
  816. * by a Taylor series.
  817. *
  818. *
  819. * ACCURACY:
  820. *
  821. * Relative error:
  822. * arithmetic domain # trials peak rms
  823. * DEC -10,+10 3000 6.5e-17 1.6e-17
  824. * IEEE -10,+10 30000 9.2e-16 1.2e-16
  825. * Also tested by ctan * ccot = 1 + i0.
  826. */
  827. /* casinl()
  828. *
  829. * Complex circular arc sine
  830. *
  831. *
  832. *
  833. * SYNOPSIS:
  834. *
  835. * void casinl();
  836. * cmplxl z, w;
  837. *
  838. * casinl( &z, &w );
  839. *
  840. *
  841. *
  842. * DESCRIPTION:
  843. *
  844. * Inverse complex sine:
  845. *
  846. * 2
  847. * w = -i clog( iz + csqrt( 1 - z ) ).
  848. *
  849. *
  850. * ACCURACY:
  851. *
  852. * Relative error:
  853. * arithmetic domain # trials peak rms
  854. * DEC -10,+10 10100 2.1e-15 3.4e-16
  855. * IEEE -10,+10 30000 2.2e-14 2.7e-15
  856. * Larger relative error can be observed for z near zero.
  857. * Also tested by csin(casin(z)) = z.
  858. */
  859. /* cacosl()
  860. *
  861. * Complex circular arc cosine
  862. *
  863. *
  864. *
  865. * SYNOPSIS:
  866. *
  867. * void cacosl();
  868. * cmplxl z, w;
  869. *
  870. * cacosl( &z, &w );
  871. *
  872. *
  873. *
  874. * DESCRIPTION:
  875. *
  876. *
  877. * w = arccos z = PI/2 - arcsin z.
  878. *
  879. *
  880. *
  881. *
  882. * ACCURACY:
  883. *
  884. * Relative error:
  885. * arithmetic domain # trials peak rms
  886. * DEC -10,+10 5200 1.6e-15 2.8e-16
  887. * IEEE -10,+10 30000 1.8e-14 2.2e-15
  888. */
  889. /* catanl()
  890. *
  891. * Complex circular arc tangent
  892. *
  893. *
  894. *
  895. * SYNOPSIS:
  896. *
  897. * void catanl();
  898. * cmplxl z, w;
  899. *
  900. * catanl( &z, &w );
  901. *
  902. *
  903. *
  904. * DESCRIPTION:
  905. *
  906. * If
  907. * z = x + iy,
  908. *
  909. * then
  910. * 1 ( 2x )
  911. * Re w = - arctan(-----------) + k PI
  912. * 2 ( 2 2)
  913. * (1 - x - y )
  914. *
  915. * ( 2 2)
  916. * 1 (x + (y+1) )
  917. * Im w = - log(------------)
  918. * 4 ( 2 2)
  919. * (x + (y-1) )
  920. *
  921. * Where k is an arbitrary integer.
  922. *
  923. *
  924. *
  925. * ACCURACY:
  926. *
  927. * Relative error:
  928. * arithmetic domain # trials peak rms
  929. * DEC -10,+10 5900 1.3e-16 7.8e-18
  930. * IEEE -10,+10 30000 2.3e-15 8.5e-17
  931. * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2,
  932. * had peak relative error 1.5e-16, rms relative error
  933. * 2.9e-17. See also clog().
  934. */
  935. /* cmplxl.c
  936. *
  937. * Complex number arithmetic
  938. *
  939. *
  940. *
  941. * SYNOPSIS:
  942. *
  943. * typedef struct {
  944. * long double r; real part
  945. * long double i; imaginary part
  946. * }cmplxl;
  947. *
  948. * cmplxl *a, *b, *c;
  949. *
  950. * caddl( a, b, c ); c = b + a
  951. * csubl( a, b, c ); c = b - a
  952. * cmull( a, b, c ); c = b * a
  953. * cdivl( a, b, c ); c = b / a
  954. * cnegl( c ); c = -c
  955. * cmovl( b, c ); c = b
  956. *
  957. *
  958. *
  959. * DESCRIPTION:
  960. *
  961. * Addition:
  962. * c.r = b.r + a.r
  963. * c.i = b.i + a.i
  964. *
  965. * Subtraction:
  966. * c.r = b.r - a.r
  967. * c.i = b.i - a.i
  968. *
  969. * Multiplication:
  970. * c.r = b.r * a.r - b.i * a.i
  971. * c.i = b.r * a.i + b.i * a.r
  972. *
  973. * Division:
  974. * d = a.r * a.r + a.i * a.i
  975. * c.r = (b.r * a.r + b.i * a.i)/d
  976. * c.i = (b.i * a.r - b.r * a.i)/d
  977. * ACCURACY:
  978. *
  979. * In DEC arithmetic, the test (1/z) * z = 1 had peak relative
  980. * error 3.1e-17, rms 1.2e-17. The test (y/z) * (z/y) = 1 had
  981. * peak relative error 8.3e-17, rms 2.1e-17.
  982. *
  983. * Tests in the rectangle {-10,+10}:
  984. * Relative error:
  985. * arithmetic function # trials peak rms
  986. * DEC cadd 10000 1.4e-17 3.4e-18
  987. * IEEE cadd 100000 1.1e-16 2.7e-17
  988. * DEC csub 10000 1.4e-17 4.5e-18
  989. * IEEE csub 100000 1.1e-16 3.4e-17
  990. * DEC cmul 3000 2.3e-17 8.7e-18
  991. * IEEE cmul 100000 2.1e-16 6.9e-17
  992. * DEC cdiv 18000 4.9e-17 1.3e-17
  993. * IEEE cdiv 100000 3.7e-16 1.1e-16
  994. */
  995. /* cabsl()
  996. *
  997. * Complex absolute value
  998. *
  999. *
  1000. *
  1001. * SYNOPSIS:
  1002. *
  1003. * long double cabsl();
  1004. * cmplxl z;
  1005. * long double a;
  1006. *
  1007. * a = cabs( &z );
  1008. *
  1009. *
  1010. *
  1011. * DESCRIPTION:
  1012. *
  1013. *
  1014. * If z = x + iy
  1015. *
  1016. * then
  1017. *
  1018. * a = sqrt( x**2 + y**2 ).
  1019. *
  1020. * Overflow and underflow are avoided by testing the magnitudes
  1021. * of x and y before squaring. If either is outside half of
  1022. * the floating point full scale range, both are rescaled.
  1023. *
  1024. *
  1025. * ACCURACY:
  1026. *
  1027. * Relative error:
  1028. * arithmetic domain # trials peak rms
  1029. * DEC -30,+30 30000 3.2e-17 9.2e-18
  1030. * IEEE -10,+10 100000 2.7e-16 6.9e-17
  1031. */
  1032. /* csqrtl()
  1033. *
  1034. * Complex square root
  1035. *
  1036. *
  1037. *
  1038. * SYNOPSIS:
  1039. *
  1040. * void csqrtl();
  1041. * cmplxl z, w;
  1042. *
  1043. * csqrtl( &z, &w );
  1044. *
  1045. *
  1046. *
  1047. * DESCRIPTION:
  1048. *
  1049. *
  1050. * If z = x + iy, r = |z|, then
  1051. *
  1052. * 1/2
  1053. * Im w = [ (r - x)/2 ] ,
  1054. *
  1055. * Re w = y / 2 Im w.
  1056. *
  1057. *
  1058. * Note that -w is also a square root of z. The root chosen
  1059. * is always in the upper half plane.
  1060. *
  1061. * Because of the potential for cancellation error in r - x,
  1062. * the result is sharpened by doing a Heron iteration
  1063. * (see sqrt.c) in complex arithmetic.
  1064. *
  1065. *
  1066. *
  1067. * ACCURACY:
  1068. *
  1069. * Relative error:
  1070. * arithmetic domain # trials peak rms
  1071. * DEC -10,+10 25000 3.2e-17 9.6e-18
  1072. * IEEE -10,+10 100000 3.2e-16 7.7e-17
  1073. *
  1074. * 2
  1075. * Also tested by csqrt( z ) = z, and tested by arguments
  1076. * close to the real axis.
  1077. */
  1078. /* coshl.c
  1079. *
  1080. * Hyperbolic cosine, long double precision
  1081. *
  1082. *
  1083. *
  1084. * SYNOPSIS:
  1085. *
  1086. * long double x, y, coshl();
  1087. *
  1088. * y = coshl( x );
  1089. *
  1090. *
  1091. *
  1092. * DESCRIPTION:
  1093. *
  1094. * Returns hyperbolic cosine of argument in the range MINLOGL to
  1095. * MAXLOGL.
  1096. *
  1097. * cosh(x) = ( exp(x) + exp(-x) )/2.
  1098. *
  1099. *
  1100. *
  1101. * ACCURACY:
  1102. *
  1103. * Relative error:
  1104. * arithmetic domain # trials peak rms
  1105. * IEEE +-10000 30000 1.1e-19 2.8e-20
  1106. *
  1107. *
  1108. * ERROR MESSAGES:
  1109. *
  1110. * message condition value returned
  1111. * cosh overflow |x| > MAXLOGL MAXNUML
  1112. *
  1113. *
  1114. */
  1115. /* elliel.c
  1116. *
  1117. * Incomplete elliptic integral of the second kind
  1118. *
  1119. *
  1120. *
  1121. * SYNOPSIS:
  1122. *
  1123. * long double phi, m, y, elliel();
  1124. *
  1125. * y = elliel( phi, m );
  1126. *
  1127. *
  1128. *
  1129. * DESCRIPTION:
  1130. *
  1131. * Approximates the integral
  1132. *
  1133. *
  1134. * phi
  1135. * -
  1136. * | |
  1137. * | 2
  1138. * E(phi_\m) = | sqrt( 1 - m sin t ) dt
  1139. * |
  1140. * | |
  1141. * -
  1142. * 0
  1143. *
  1144. * of amplitude phi and modulus m, using the arithmetic -
  1145. * geometric mean algorithm.
  1146. *
  1147. *
  1148. *
  1149. * ACCURACY:
  1150. *
  1151. * Tested at random arguments with phi in [-10, 10] and m in
  1152. * [0, 1].
  1153. * Relative error:
  1154. * arithmetic domain # trials peak rms
  1155. * IEEE -10,10 50000 2.7e-18 2.3e-19
  1156. *
  1157. *
  1158. */
  1159. /* ellikl.c
  1160. *
  1161. * Incomplete elliptic integral of the first kind
  1162. *
  1163. *
  1164. *
  1165. * SYNOPSIS:
  1166. *
  1167. * long double phi, m, y, ellikl();
  1168. *
  1169. * y = ellikl( phi, m );
  1170. *
  1171. *
  1172. *
  1173. * DESCRIPTION:
  1174. *
  1175. * Approximates the integral
  1176. *
  1177. *
  1178. *
  1179. * phi
  1180. * -
  1181. * | |
  1182. * | dt
  1183. * F(phi_\m) = | ------------------
  1184. * | 2
  1185. * | | sqrt( 1 - m sin t )
  1186. * -
  1187. * 0
  1188. *
  1189. * of amplitude phi and modulus m, using the arithmetic -
  1190. * geometric mean algorithm.
  1191. *
  1192. *
  1193. *
  1194. *
  1195. * ACCURACY:
  1196. *
  1197. * Tested at random points with m in [0, 1] and phi as indicated.
  1198. *
  1199. * Relative error:
  1200. * arithmetic domain # trials peak rms
  1201. * IEEE -10,10 30000 3.6e-18 4.1e-19
  1202. *
  1203. *
  1204. */
  1205. /* ellpel.c
  1206. *
  1207. * Complete elliptic integral of the second kind
  1208. *
  1209. *
  1210. *
  1211. * SYNOPSIS:
  1212. *
  1213. * long double m1, y, ellpel();
  1214. *
  1215. * y = ellpel( m1 );
  1216. *
  1217. *
  1218. *
  1219. * DESCRIPTION:
  1220. *
  1221. * Approximates the integral
  1222. *
  1223. *
  1224. * pi/2
  1225. * -
  1226. * | | 2
  1227. * E(m) = | sqrt( 1 - m sin t ) dt
  1228. * | |
  1229. * -
  1230. * 0
  1231. *
  1232. * Where m = 1 - m1, using the approximation
  1233. *
  1234. * P(x) - x log x Q(x).
  1235. *
  1236. * Though there are no singularities, the argument m1 is used
  1237. * rather than m for compatibility with ellpk().
  1238. *
  1239. * E(1) = 1; E(0) = pi/2.
  1240. *
  1241. *
  1242. * ACCURACY:
  1243. *
  1244. * Relative error:
  1245. * arithmetic domain # trials peak rms
  1246. * IEEE 0, 1 10000 1.1e-19 3.5e-20
  1247. *
  1248. *
  1249. * ERROR MESSAGES:
  1250. *
  1251. * message condition value returned
  1252. * ellpel domain x<0, x>1 0.0
  1253. *
  1254. */
  1255. /* ellpjl.c
  1256. *
  1257. * Jacobian Elliptic Functions
  1258. *
  1259. *
  1260. *
  1261. * SYNOPSIS:
  1262. *
  1263. * long double u, m, sn, cn, dn, phi;
  1264. * int ellpjl();
  1265. *
  1266. * ellpjl( u, m, _&sn, _&cn, _&dn, _&phi );
  1267. *
  1268. *
  1269. *
  1270. * DESCRIPTION:
  1271. *
  1272. *
  1273. * Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
  1274. * and dn(u|m) of parameter m between 0 and 1, and real
  1275. * argument u.
  1276. *
  1277. * These functions are periodic, with quarter-period on the
  1278. * real axis equal to the complete elliptic integral
  1279. * ellpk(1.0-m).
  1280. *
  1281. * Relation to incomplete elliptic integral:
  1282. * If u = ellik(phi,m), then sn(u|m) = sin(phi),
  1283. * and cn(u|m) = cos(phi). Phi is called the amplitude of u.
  1284. *
  1285. * Computation is by means of the arithmetic-geometric mean
  1286. * algorithm, except when m is within 1e-12 of 0 or 1. In the
  1287. * latter case with m close to 1, the approximation applies
  1288. * only for phi < pi/2.
  1289. *
  1290. * ACCURACY:
  1291. *
  1292. * Tested at random points with u between 0 and 10, m between
  1293. * 0 and 1.
  1294. *
  1295. * Absolute error (* = relative error):
  1296. * arithmetic function # trials peak rms
  1297. * IEEE sn 10000 1.7e-18 2.3e-19
  1298. * IEEE cn 20000 1.6e-18 2.2e-19
  1299. * IEEE dn 10000 4.7e-15 2.7e-17
  1300. * IEEE phi 10000 4.0e-19* 6.6e-20*
  1301. *
  1302. * Accuracy deteriorates when u is large.
  1303. *
  1304. */
  1305. /* ellpkl.c
  1306. *
  1307. * Complete elliptic integral of the first kind
  1308. *
  1309. *
  1310. *
  1311. * SYNOPSIS:
  1312. *
  1313. * long double m1, y, ellpkl();
  1314. *
  1315. * y = ellpkl( m1 );
  1316. *
  1317. *
  1318. *
  1319. * DESCRIPTION:
  1320. *
  1321. * Approximates the integral
  1322. *
  1323. *
  1324. *
  1325. * pi/2
  1326. * -
  1327. * | |
  1328. * | dt
  1329. * K(m) = | ------------------
  1330. * | 2
  1331. * | | sqrt( 1 - m sin t )
  1332. * -
  1333. * 0
  1334. *
  1335. * where m = 1 - m1, using the approximation
  1336. *
  1337. * P(x) - log x Q(x).
  1338. *
  1339. * The argument m1 is used rather than m so that the logarithmic
  1340. * singularity at m = 1 will be shifted to the origin; this
  1341. * preserves maximum accuracy.
  1342. *
  1343. * K(0) = pi/2.
  1344. *
  1345. * ACCURACY:
  1346. *
  1347. * Relative error:
  1348. * arithmetic domain # trials peak rms
  1349. * IEEE 0,1 10000 1.1e-19 3.3e-20
  1350. *
  1351. * ERROR MESSAGES:
  1352. *
  1353. * message condition value returned
  1354. * ellpkl domain x<0, x>1 0.0
  1355. *
  1356. */
  1357. /* exp10l.c
  1358. *
  1359. * Base 10 exponential function, long double precision
  1360. * (Common antilogarithm)
  1361. *
  1362. *
  1363. *
  1364. * SYNOPSIS:
  1365. *
  1366. * long double x, y, exp10l()
  1367. *
  1368. * y = exp10l( x );
  1369. *
  1370. *
  1371. *
  1372. * DESCRIPTION:
  1373. *
  1374. * Returns 10 raised to the x power.
  1375. *
  1376. * Range reduction is accomplished by expressing the argument
  1377. * as 10**x = 2**n 10**f, with |f| < 0.5 log10(2).
  1378. * The Pade' form
  1379. *
  1380. * 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
  1381. *
  1382. * is used to approximate 10**f.
  1383. *
  1384. *
  1385. *
  1386. * ACCURACY:
  1387. *
  1388. * Relative error:
  1389. * arithmetic domain # trials peak rms
  1390. * IEEE +-4900 30000 1.0e-19 2.7e-20
  1391. *
  1392. * ERROR MESSAGES:
  1393. *
  1394. * message condition value returned
  1395. * exp10l underflow x < -MAXL10 0.0
  1396. * exp10l overflow x > MAXL10 MAXNUM
  1397. *
  1398. * IEEE arithmetic: MAXL10 = 4932.0754489586679023819
  1399. *
  1400. */
  1401. /* exp2l.c
  1402. *
  1403. * Base 2 exponential function, long double precision
  1404. *
  1405. *
  1406. *
  1407. * SYNOPSIS:
  1408. *
  1409. * long double x, y, exp2l();
  1410. *
  1411. * y = exp2l( x );
  1412. *
  1413. *
  1414. *
  1415. * DESCRIPTION:
  1416. *
  1417. * Returns 2 raised to the x power.
  1418. *
  1419. * Range reduction is accomplished by separating the argument
  1420. * into an integer k and fraction f such that
  1421. * x k f
  1422. * 2 = 2 2.
  1423. *
  1424. * A Pade' form
  1425. *
  1426. * 1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
  1427. *
  1428. * approximates 2**x in the basic range [-0.5, 0.5].
  1429. *
  1430. *
  1431. * ACCURACY:
  1432. *
  1433. * Relative error:
  1434. * arithmetic domain # trials peak rms
  1435. * IEEE +-16300 300000 9.1e-20 2.6e-20
  1436. *
  1437. *
  1438. * See exp.c for comments on error amplification.
  1439. *
  1440. *
  1441. * ERROR MESSAGES:
  1442. *
  1443. * message condition value returned
  1444. * exp2l underflow x < -16382 0.0
  1445. * exp2l overflow x >= 16384 MAXNUM
  1446. *
  1447. */
  1448. /* expl.c
  1449. *
  1450. * Exponential function, long double precision
  1451. *
  1452. *
  1453. *
  1454. * SYNOPSIS:
  1455. *
  1456. * long double x, y, expl();
  1457. *
  1458. * y = expl( x );
  1459. *
  1460. *
  1461. *
  1462. * DESCRIPTION:
  1463. *
  1464. * Returns e (2.71828...) raised to the x power.
  1465. *
  1466. * Range reduction is accomplished by separating the argument
  1467. * into an integer k and fraction f such that
  1468. *
  1469. * x k f
  1470. * e = 2 e.
  1471. *
  1472. * A Pade' form of degree 2/3 is used to approximate exp(f) - 1
  1473. * in the basic range [-0.5 ln 2, 0.5 ln 2].
  1474. *
  1475. *
  1476. * ACCURACY:
  1477. *
  1478. * Relative error:
  1479. * arithmetic domain # trials peak rms
  1480. * IEEE +-10000 50000 1.12e-19 2.81e-20
  1481. *
  1482. *
  1483. * Error amplification in the exponential function can be
  1484. * a serious matter. The error propagation involves
  1485. * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),
  1486. * which shows that a 1 lsb error in representing X produces
  1487. * a relative error of X times 1 lsb in the function.
  1488. * While the routine gives an accurate result for arguments
  1489. * that are exactly represented by a long double precision
  1490. * computer number, the result contains amplified roundoff
  1491. * error for large arguments not exactly represented.
  1492. *
  1493. *
  1494. * ERROR MESSAGES:
  1495. *
  1496. * message condition value returned
  1497. * exp underflow x < MINLOG 0.0
  1498. * exp overflow x > MAXLOG MAXNUM
  1499. *
  1500. */
  1501. /* fabsl.c
  1502. *
  1503. * Absolute value
  1504. *
  1505. *
  1506. *
  1507. * SYNOPSIS:
  1508. *
  1509. * long double x, y;
  1510. *
  1511. * y = fabsl( x );
  1512. *
  1513. *
  1514. *
  1515. * DESCRIPTION:
  1516. *
  1517. * Returns the absolute value of the argument.
  1518. *
  1519. */
  1520. /* fdtrl.c
  1521. *
  1522. * F distribution, long double precision
  1523. *
  1524. *
  1525. *
  1526. * SYNOPSIS:
  1527. *
  1528. * int df1, df2;
  1529. * long double x, y, fdtrl();
  1530. *
  1531. * y = fdtrl( df1, df2, x );
  1532. *
  1533. *
  1534. *
  1535. * DESCRIPTION:
  1536. *
  1537. * Returns the area from zero to x under the F density
  1538. * function (also known as Snedcor's density or the
  1539. * variance ratio density). This is the density
  1540. * of x = (u1/df1)/(u2/df2), where u1 and u2 are random
  1541. * variables having Chi square distributions with df1
  1542. * and df2 degrees of freedom, respectively.
  1543. *
  1544. * The incomplete beta integral is used, according to the
  1545. * formula
  1546. *
  1547. * P(x) = incbetl( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
  1548. *
  1549. *
  1550. * The arguments a and b are greater than zero, and x
  1551. * x is nonnegative.
  1552. *
  1553. * ACCURACY:
  1554. *
  1555. * Tested at random points (a,b,x) in the indicated intervals.
  1556. * x a,b Relative error:
  1557. * arithmetic domain domain # trials peak rms
  1558. * IEEE 0,1 1,100 10000 9.3e-18 2.9e-19
  1559. * IEEE 0,1 1,10000 10000 1.9e-14 2.9e-15
  1560. * IEEE 1,5 1,10000 10000 5.8e-15 1.4e-16
  1561. *
  1562. * ERROR MESSAGES:
  1563. *
  1564. * message condition value returned
  1565. * fdtrl domain a<0, b<0, x<0 0.0
  1566. *
  1567. */
  1568. /* fdtrcl()
  1569. *
  1570. * Complemented F distribution
  1571. *
  1572. *
  1573. *
  1574. * SYNOPSIS:
  1575. *
  1576. * int df1, df2;
  1577. * long double x, y, fdtrcl();
  1578. *
  1579. * y = fdtrcl( df1, df2, x );
  1580. *
  1581. *
  1582. *
  1583. * DESCRIPTION:
  1584. *
  1585. * Returns the area from x to infinity under the F density
  1586. * function (also known as Snedcor's density or the
  1587. * variance ratio density).
  1588. *
  1589. *
  1590. * inf.
  1591. * -
  1592. * 1 | | a-1 b-1
  1593. * 1-P(x) = ------ | t (1-t) dt
  1594. * B(a,b) | |
  1595. * -
  1596. * x
  1597. *
  1598. * (See fdtr.c.)
  1599. *
  1600. * The incomplete beta integral is used, according to the
  1601. * formula
  1602. *
  1603. * P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
  1604. *
  1605. *
  1606. * ACCURACY:
  1607. *
  1608. * See incbet.c.
  1609. * Tested at random points (a,b,x).
  1610. *
  1611. * x a,b Relative error:
  1612. * arithmetic domain domain # trials peak rms
  1613. * IEEE 0,1 0,100 10000 4.2e-18 3.3e-19
  1614. * IEEE 0,1 1,10000 10000 7.2e-15 2.6e-16
  1615. * IEEE 1,5 1,10000 10000 1.7e-14 3.0e-15
  1616. *
  1617. * ERROR MESSAGES:
  1618. *
  1619. * message condition value returned
  1620. * fdtrcl domain a<0, b<0, x<0 0.0
  1621. *
  1622. */
  1623. /* fdtril()
  1624. *
  1625. * Inverse of complemented F distribution
  1626. *
  1627. *
  1628. *
  1629. * SYNOPSIS:
  1630. *
  1631. * int df1, df2;
  1632. * long double x, p, fdtril();
  1633. *
  1634. * x = fdtril( df1, df2, p );
  1635. *
  1636. * DESCRIPTION:
  1637. *
  1638. * Finds the F density argument x such that the integral
  1639. * from x to infinity of the F density is equal to the
  1640. * given probability p.
  1641. *
  1642. * This is accomplished using the inverse beta integral
  1643. * function and the relations
  1644. *
  1645. * z = incbi( df2/2, df1/2, p )
  1646. * x = df2 (1-z) / (df1 z).
  1647. *
  1648. * Note: the following relations hold for the inverse of
  1649. * the uncomplemented F distribution:
  1650. *
  1651. * z = incbi( df1/2, df2/2, p )
  1652. * x = df2 z / (df1 (1-z)).
  1653. *
  1654. * ACCURACY:
  1655. *
  1656. * See incbi.c.
  1657. * Tested at random points (a,b,p).
  1658. *
  1659. * a,b Relative error:
  1660. * arithmetic domain # trials peak rms
  1661. * For p between .001 and 1:
  1662. * IEEE 1,100 40000 4.6e-18 2.7e-19
  1663. * IEEE 1,10000 30000 1.7e-14 1.4e-16
  1664. * For p between 10^-6 and .001:
  1665. * IEEE 1,100 20000 1.9e-15 3.9e-17
  1666. * IEEE 1,10000 30000 2.7e-15 4.0e-17
  1667. *
  1668. * ERROR MESSAGES:
  1669. *
  1670. * message condition value returned
  1671. * fdtril domain p <= 0 or p > 1 0.0
  1672. * v < 1
  1673. */
  1674. /* ceill()
  1675. * floorl()
  1676. * frexpl()
  1677. * ldexpl()
  1678. * fabsl()
  1679. *
  1680. * Floating point numeric utilities
  1681. *
  1682. *
  1683. *
  1684. * SYNOPSIS:
  1685. *
  1686. * long double x, y;
  1687. * long double ceill(), floorl(), frexpl(), ldexpl(), fabsl();
  1688. * int expnt, n;
  1689. *
  1690. * y = floorl(x);
  1691. * y = ceill(x);
  1692. * y = frexpl( x, &expnt );
  1693. * y = ldexpl( x, n );
  1694. * y = fabsl( x );
  1695. *
  1696. *
  1697. *
  1698. * DESCRIPTION:
  1699. *
  1700. * All four routines return a long double precision floating point
  1701. * result.
  1702. *
  1703. * floorl() returns the largest integer less than or equal to x.
  1704. * It truncates toward minus infinity.
  1705. *
  1706. * ceill() returns the smallest integer greater than or equal
  1707. * to x. It truncates toward plus infinity.
  1708. *
  1709. * frexpl() extracts the exponent from x. It returns an integer
  1710. * power of two to expnt and the significand between 0.5 and 1
  1711. * to y. Thus x = y * 2**expn.
  1712. *
  1713. * ldexpl() multiplies x by 2**n.
  1714. *
  1715. * fabsl() returns the absolute value of its argument.
  1716. *
  1717. * These functions are part of the standard C run time library
  1718. * for some but not all C compilers. The ones supplied are
  1719. * written in C for IEEE arithmetic. They should
  1720. * be used only if your compiler library does not already have
  1721. * them.
  1722. *
  1723. * The IEEE versions assume that denormal numbers are implemented
  1724. * in the arithmetic. Some modifications will be required if
  1725. * the arithmetic has abrupt rather than gradual underflow.
  1726. */
  1727. /* gammal.c
  1728. *
  1729. * Gamma function
  1730. *
  1731. *
  1732. *
  1733. * SYNOPSIS:
  1734. *
  1735. * long double x, y, gammal();
  1736. * extern int sgngam;
  1737. *
  1738. * y = gammal( x );
  1739. *
  1740. *
  1741. *
  1742. * DESCRIPTION:
  1743. *
  1744. * Returns gamma function of the argument. The result is
  1745. * correctly signed, and the sign (+1 or -1) is also
  1746. * returned in a global (extern) variable named sgngam.
  1747. * This variable is also filled in by the logarithmic gamma
  1748. * function lgam().
  1749. *
  1750. * Arguments |x| <= 13 are reduced by recurrence and the function
  1751. * approximated by a rational function of degree 7/8 in the
  1752. * interval (2,3). Large arguments are handled by Stirling's
  1753. * formula. Large negative arguments are made positive using
  1754. * a reflection formula.
  1755. *
  1756. *
  1757. * ACCURACY:
  1758. *
  1759. * Relative error:
  1760. * arithmetic domain # trials peak rms
  1761. * IEEE -40,+40 10000 3.6e-19 7.9e-20
  1762. * IEEE -1755,+1755 10000 4.8e-18 6.5e-19
  1763. *
  1764. * Accuracy for large arguments is dominated by error in powl().
  1765. *
  1766. */
  1767. /* lgaml()
  1768. *
  1769. * Natural logarithm of gamma function
  1770. *
  1771. *
  1772. *
  1773. * SYNOPSIS:
  1774. *
  1775. * long double x, y, lgaml();
  1776. * extern int sgngam;
  1777. *
  1778. * y = lgaml( x );
  1779. *
  1780. *
  1781. *
  1782. * DESCRIPTION:
  1783. *
  1784. * Returns the base e (2.718...) logarithm of the absolute
  1785. * value of the gamma function of the argument.
  1786. * The sign (+1 or -1) of the gamma function is returned in a
  1787. * global (extern) variable named sgngam.
  1788. *
  1789. * For arguments greater than 33, the logarithm of the gamma
  1790. * function is approximated by the logarithmic version of
  1791. * Stirling's formula using a polynomial approximation of
  1792. * degree 4. Arguments between -33 and +33 are reduced by
  1793. * recurrence to the interval [2,3] of a rational approximation.
  1794. * The cosecant reflection formula is employed for arguments
  1795. * less than -33.
  1796. *
  1797. * Arguments greater than MAXLGML (10^4928) return MAXNUML.
  1798. *
  1799. *
  1800. *
  1801. * ACCURACY:
  1802. *
  1803. *
  1804. * arithmetic domain # trials peak rms
  1805. * IEEE -40, 40 100000 2.2e-19 4.6e-20
  1806. * IEEE 10^-2000,10^+2000 20000 1.6e-19 3.3e-20
  1807. * The error criterion was relative when the function magnitude
  1808. * was greater than one but absolute when it was less than one.
  1809. *
  1810. */
  1811. /* gdtrl.c
  1812. *
  1813. * Gamma distribution function
  1814. *
  1815. *
  1816. *
  1817. * SYNOPSIS:
  1818. *
  1819. * long double a, b, x, y, gdtrl();
  1820. *
  1821. * y = gdtrl( a, b, x );
  1822. *
  1823. *
  1824. *
  1825. * DESCRIPTION:
  1826. *
  1827. * Returns the integral from zero to x of the gamma probability
  1828. * density function:
  1829. *
  1830. *
  1831. * x
  1832. * b -
  1833. * a | | b-1 -at
  1834. * y = ----- | t e dt
  1835. * - | |
  1836. * | (b) -
  1837. * 0
  1838. *
  1839. * The incomplete gamma integral is used, according to the
  1840. * relation
  1841. *
  1842. * y = igam( b, ax ).
  1843. *
  1844. *
  1845. * ACCURACY:
  1846. *
  1847. * See igam().
  1848. *
  1849. * ERROR MESSAGES:
  1850. *
  1851. * message condition value returned
  1852. * gdtrl domain x < 0 0.0
  1853. *
  1854. */
  1855. /* gdtrcl.c
  1856. *
  1857. * Complemented gamma distribution function
  1858. *
  1859. *
  1860. *
  1861. * SYNOPSIS:
  1862. *
  1863. * long double a, b, x, y, gdtrcl();
  1864. *
  1865. * y = gdtrcl( a, b, x );
  1866. *
  1867. *
  1868. *
  1869. * DESCRIPTION:
  1870. *
  1871. * Returns the integral from x to infinity of the gamma
  1872. * probability density function:
  1873. *
  1874. *
  1875. * inf.
  1876. * b -
  1877. * a | | b-1 -at
  1878. * y = ----- | t e dt
  1879. * - | |
  1880. * | (b) -
  1881. * x
  1882. *
  1883. * The incomplete gamma integral is used, according to the
  1884. * relation
  1885. *
  1886. * y = igamc( b, ax ).
  1887. *
  1888. *
  1889. * ACCURACY:
  1890. *
  1891. * See igamc().
  1892. *
  1893. * ERROR MESSAGES:
  1894. *
  1895. * message condition value returned
  1896. * gdtrcl domain x < 0 0.0
  1897. *
  1898. */
  1899. /*
  1900. C
  1901. C ..................................................................
  1902. C
  1903. C SUBROUTINE GELS
  1904. C
  1905. C PURPOSE
  1906. C TO SOLVE A SYSTEM OF SIMULTANEOUS LINEAR EQUATIONS WITH
  1907. C SYMMETRIC COEFFICIENT MATRIX UPPER TRIANGULAR PART OF WHICH
  1908. C IS ASSUMED TO BE STORED COLUMNWISE.
  1909. C
  1910. C USAGE
  1911. C CALL GELS(R,A,M,N,EPS,IER,AUX)
  1912. C
  1913. C DESCRIPTION OF PARAMETERS
  1914. C R - M BY N RIGHT HAND SIDE MATRIX. (DESTROYED)
  1915. C ON RETURN R CONTAINS THE SOLUTION OF THE EQUATIONS.
  1916. C A - UPPER TRIANGULAR PART OF THE SYMMETRIC
  1917. C M BY M COEFFICIENT MATRIX. (DESTROYED)
  1918. C M - THE NUMBER OF EQUATIONS IN THE SYSTEM.
  1919. C N - THE NUMBER OF RIGHT HAND SIDE VECTORS.
  1920. C EPS - AN INPUT CONSTANT WHICH IS USED AS RELATIVE
  1921. C TOLERANCE FOR TEST ON LOSS OF SIGNIFICANCE.
  1922. C IER - RESULTING ERROR PARAMETER CODED AS FOLLOWS
  1923. C IER=0 - NO ERROR,
  1924. C IER=-1 - NO RESULT BECAUSE OF M LESS THAN 1 OR
  1925. C PIVOT ELEMENT AT ANY ELIMINATION STEP
  1926. C EQUAL TO 0,
  1927. C IER=K - WARNING DUE TO POSSIBLE LOSS OF SIGNIFI-
  1928. C CANCE INDICATED AT ELIMINATION STEP K+1,
  1929. C WHERE PIVOT ELEMENT WAS LESS THAN OR
  1930. C EQUAL TO THE INTERNAL TOLERANCE EPS TIMES
  1931. C ABSOLUTELY GREATEST MAIN DIAGONAL
  1932. C ELEMENT OF MATRIX A.
  1933. C AUX - AN AUXILIARY STORAGE ARRAY WITH DIMENSION M-1.
  1934. C
  1935. C REMARKS
  1936. C UPPER TRIANGULAR PART OF MATRIX A IS ASSUMED TO BE STORED
  1937. C COLUMNWISE IN M*(M+1)/2 SUCCESSIVE STORAGE LOCATIONS, RIGHT
  1938. C HAND SIDE MATRIX R COLUMNWISE IN N*M SUCCESSIVE STORAGE
  1939. C LOCATIONS. ON RETURN SOLUTION MATRIX R IS STORED COLUMNWISE
  1940. C TOO.
  1941. C THE PROCEDURE GIVES RESULTS IF THE NUMBER OF EQUATIONS M IS
  1942. C GREATER THAN 0 AND PIVOT ELEMENTS AT ALL ELIMINATION STEPS
  1943. C ARE DIFFERENT FROM 0. HOWEVER WARNING IER=K - IF GIVEN -
  1944. C INDICATES POSSIBLE LOSS OF SIGNIFICANCE. IN CASE OF A WELL
  1945. C SCALED MATRIX A AND APPROPRIATE TOLERANCE EPS, IER=K MAY BE
  1946. C INTERPRETED THAT MATRIX A HAS THE RANK K. NO WARNING IS
  1947. C GIVEN IN CASE M=1.
  1948. C ERROR PARAMETER IER=-1 DOES NOT NECESSARILY MEAN THAT
  1949. C MATRIX A IS SINGULAR, AS ONLY MAIN DIAGONAL ELEMENTS
  1950. C ARE USED AS PIVOT ELEMENTS. POSSIBLY SUBROUTINE GELG (WHICH
  1951. C WORKS WITH TOTAL PIVOTING) WOULD BE ABLE TO FIND A SOLUTION.
  1952. C
  1953. C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
  1954. C NONE
  1955. C
  1956. C METHOD
  1957. C SOLUTION IS DONE BY MEANS OF GAUSS-ELIMINATION WITH
  1958. C PIVOTING IN MAIN DIAGONAL, IN ORDER TO PRESERVE
  1959. C SYMMETRY IN REMAINING COEFFICIENT MATRICES.
  1960. C
  1961. C ..................................................................
  1962. C
  1963. */
  1964. /* igamil()
  1965. *
  1966. * Inverse of complemented imcomplete gamma integral
  1967. *
  1968. *
  1969. *
  1970. * SYNOPSIS:
  1971. *
  1972. * long double a, x, y, igamil();
  1973. *
  1974. * x = igamil( a, y );
  1975. *
  1976. *
  1977. *
  1978. * DESCRIPTION:
  1979. *
  1980. * Given y, the function finds x such that
  1981. *
  1982. * igamc( a, x ) = y.
  1983. *
  1984. * Starting with the approximate value
  1985. *
  1986. * 3
  1987. * x = a t
  1988. *
  1989. * where
  1990. *
  1991. * t = 1 - d - ndtri(y) sqrt(d)
  1992. *
  1993. * and
  1994. *
  1995. * d = 1/9a,
  1996. *
  1997. * the routine performs up to 10 Newton iterations to find the
  1998. * root of igamc(a,x) - y = 0.
  1999. *
  2000. *
  2001. * ACCURACY:
  2002. *
  2003. * Tested for a ranging from 0.5 to 30 and x from 0 to 0.5.
  2004. *
  2005. * Relative error:
  2006. * arithmetic domain # trials peak rms
  2007. * DEC 0,0.5 3400 8.8e-16 1.3e-16
  2008. * IEEE 0,0.5 10000 1.1e-14 1.0e-15
  2009. *
  2010. */
  2011. /* igaml.c
  2012. *
  2013. * Incomplete gamma integral
  2014. *
  2015. *
  2016. *
  2017. * SYNOPSIS:
  2018. *
  2019. * long double a, x, y, igaml();
  2020. *
  2021. * y = igaml( a, x );
  2022. *
  2023. *
  2024. *
  2025. * DESCRIPTION:
  2026. *
  2027. * The function is defined by
  2028. *
  2029. * x
  2030. * -
  2031. * 1 | | -t a-1
  2032. * igam(a,x) = ----- | e t dt.
  2033. * - | |
  2034. * | (a) -
  2035. * 0
  2036. *
  2037. *
  2038. * In this implementation both arguments must be positive.
  2039. * The integral is evaluated by either a power series or
  2040. * continued fraction expansion, depending on the relative
  2041. * values of a and x.
  2042. *
  2043. *
  2044. *
  2045. * ACCURACY:
  2046. *
  2047. * Relative error:
  2048. * arithmetic domain # trials peak rms
  2049. * DEC 0,30 4000 4.4e-15 6.3e-16
  2050. * IEEE 0,30 10000 3.6e-14 5.1e-15
  2051. *
  2052. */
  2053. /* igamcl()
  2054. *
  2055. * Complemented incomplete gamma integral
  2056. *
  2057. *
  2058. *
  2059. * SYNOPSIS:
  2060. *
  2061. * long double a, x, y, igamcl();
  2062. *
  2063. * y = igamcl( a, x );
  2064. *
  2065. *
  2066. *
  2067. * DESCRIPTION:
  2068. *
  2069. * The function is defined by
  2070. *
  2071. *
  2072. * igamc(a,x) = 1 - igam(a,x)
  2073. *
  2074. * inf.
  2075. * -
  2076. * 1 | | -t a-1
  2077. * = ----- | e t dt.
  2078. * - | |
  2079. * | (a) -
  2080. * x
  2081. *
  2082. *
  2083. * In this implementation both arguments must be positive.
  2084. * The integral is evaluated by either a power series or
  2085. * continued fraction expansion, depending on the relative
  2086. * values of a and x.
  2087. *
  2088. *
  2089. *
  2090. * ACCURACY:
  2091. *
  2092. * Relative error:
  2093. * arithmetic domain # trials peak rms
  2094. * DEC 0,30 2000 2.7e-15 4.0e-16
  2095. * IEEE 0,30 60000 1.4e-12 6.3e-15
  2096. *
  2097. */
  2098. /* incbetl.c
  2099. *
  2100. * Incomplete beta integral
  2101. *
  2102. *
  2103. * SYNOPSIS:
  2104. *
  2105. * long double a, b, x, y, incbetl();
  2106. *
  2107. * y = incbetl( a, b, x );
  2108. *
  2109. *
  2110. * DESCRIPTION:
  2111. *
  2112. * Returns incomplete beta integral of the arguments, evaluated
  2113. * from zero to x. The function is defined as
  2114. *
  2115. * x
  2116. * - -
  2117. * | (a+b) | | a-1 b-1
  2118. * ----------- | t (1-t) dt.
  2119. * - - | |
  2120. * | (a) | (b) -
  2121. * 0
  2122. *
  2123. * The domain of definition is 0 <= x <= 1. In this
  2124. * implementation a and b are restricted to positive values.
  2125. * The integral from x to 1 may be obtained by the symmetry
  2126. * relation
  2127. *
  2128. * 1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
  2129. *
  2130. * The integral is evaluated by a continued fraction expansion
  2131. * or, when b*x is small, by a power series.
  2132. *
  2133. * ACCURACY:
  2134. *
  2135. * Tested at random points (a,b,x) with x between 0 and 1.
  2136. * arithmetic domain # trials peak rms
  2137. * IEEE 0,5 20000 4.5e-18 2.4e-19
  2138. * IEEE 0,100 100000 3.9e-17 1.0e-17
  2139. * Half-integer a, b:
  2140. * IEEE .5,10000 100000 3.9e-14 4.4e-15
  2141. * Outputs smaller than the IEEE gradual underflow threshold
  2142. * were excluded from these statistics.
  2143. *
  2144. * ERROR MESSAGES:
  2145. *
  2146. * message condition value returned
  2147. * incbetl domain x<0, x>1 0.0
  2148. */
  2149. /* incbil()
  2150. *
  2151. * Inverse of imcomplete beta integral
  2152. *
  2153. *
  2154. *
  2155. * SYNOPSIS:
  2156. *
  2157. * long double a, b, x, y, incbil();
  2158. *
  2159. * x = incbil( a, b, y );
  2160. *
  2161. *
  2162. *
  2163. * DESCRIPTION:
  2164. *
  2165. * Given y, the function finds x such that
  2166. *
  2167. * incbet( a, b, x ) = y.
  2168. *
  2169. * the routine performs up to 10 Newton iterations to find the
  2170. * root of incbet(a,b,x) - y = 0.
  2171. *
  2172. *
  2173. * ACCURACY:
  2174. *
  2175. * Relative error:
  2176. * x a,b
  2177. * arithmetic domain domain # trials peak rms
  2178. * IEEE 0,1 .5,10000 10000 1.1e-14 1.4e-16
  2179. */
  2180. /* j0l.c
  2181. *
  2182. * Bessel function of order zero
  2183. *
  2184. *
  2185. *
  2186. * SYNOPSIS:
  2187. *
  2188. * long double x, y, j0l();
  2189. *
  2190. * y = j0l( x );
  2191. *
  2192. *
  2193. *
  2194. * DESCRIPTION:
  2195. *
  2196. * Returns Bessel function of first kind, order zero of the argument.
  2197. *
  2198. * The domain is divided into the intervals [0, 9] and
  2199. * (9, infinity). In the first interval the rational approximation
  2200. * is (x^2 - r^2) (x^2 - s^2) (x^2 - t^2) P7(x^2) / Q8(x^2),
  2201. * where r, s, t are the first three zeros of the function.
  2202. * In the second interval the expansion is in terms of the
  2203. * modulus M0(x) = sqrt(J0(x)^2 + Y0(x)^2) and phase P0(x)
  2204. * = atan(Y0(x)/J0(x)). M0 is approximated by sqrt(1/x)P7(1/x)/Q7(1/x).
  2205. * The approximation to J0 is M0 * cos(x - pi/4 + 1/x P5(1/x^2)/Q6(1/x^2)).
  2206. *
  2207. *
  2208. * ACCURACY:
  2209. *
  2210. * Absolute error:
  2211. * arithmetic domain # trials peak rms
  2212. * IEEE 0, 30 100000 2.8e-19 7.4e-20
  2213. *
  2214. *
  2215. */
  2216. /* y0l.c
  2217. *
  2218. * Bessel function of the second kind, order zero
  2219. *
  2220. *
  2221. *
  2222. * SYNOPSIS:
  2223. *
  2224. * double x, y, y0l();
  2225. *
  2226. * y = y0l( x );
  2227. *
  2228. *
  2229. *
  2230. * DESCRIPTION:
  2231. *
  2232. * Returns Bessel function of the second kind, of order
  2233. * zero, of the argument.
  2234. *
  2235. * The domain is divided into the intervals [0, 5>, [5,9> and
  2236. * [9, infinity). In the first interval a rational approximation
  2237. * R(x) is employed to compute y0(x) = R(x) + 2/pi * log(x) * j0(x).
  2238. *
  2239. * In the second interval, the approximation is
  2240. * (x - p)(x - q)(x - r)(x - s)P7(x)/Q7(x)
  2241. * where p, q, r, s are zeros of y0(x).
  2242. *
  2243. * The third interval uses the same approximations to modulus
  2244. * and phase as j0(x), whence y0(x) = modulus * sin(phase).
  2245. *
  2246. * ACCURACY:
  2247. *
  2248. * Absolute error, when y0(x) < 1; else relative error:
  2249. *
  2250. * arithmetic domain # trials peak rms
  2251. * IEEE 0, 30 100000 3.4e-19 7.6e-20
  2252. *
  2253. */
  2254. /* j1l.c
  2255. *
  2256. * Bessel function of order one
  2257. *
  2258. *
  2259. *
  2260. * SYNOPSIS:
  2261. *
  2262. * long double x, y, j1l();
  2263. *
  2264. * y = j1l( x );
  2265. *
  2266. *
  2267. *
  2268. * DESCRIPTION:
  2269. *
  2270. * Returns Bessel function of order one of the argument.
  2271. *
  2272. * The domain is divided into the intervals [0, 9] and
  2273. * (9, infinity). In the first interval the rational approximation
  2274. * is (x^2 - r^2) (x^2 - s^2) (x^2 - t^2) x P8(x^2) / Q8(x^2),
  2275. * where r, s, t are the first three zeros of the function.
  2276. * In the second interval the expansion is in terms of the
  2277. * modulus M1(x) = sqrt(J1(x)^2 + Y1(x)^2) and phase P1(x)
  2278. * = atan(Y1(x)/J1(x)). M1 is approximated by sqrt(1/x)P7(1/x)/Q8(1/x).
  2279. * The approximation to j1 is M1 * cos(x - 3 pi/4 + 1/x P5(1/x^2)/Q6(1/x^2)).
  2280. *
  2281. *
  2282. * ACCURACY:
  2283. *
  2284. * Absolute error:
  2285. * arithmetic domain # trials peak rms
  2286. * IEEE 0, 30 40000 1.8e-19 5.0e-20
  2287. *
  2288. *
  2289. */
  2290. /* y1l.c
  2291. *
  2292. * Bessel function of the second kind, order zero
  2293. *
  2294. *
  2295. *
  2296. * SYNOPSIS:
  2297. *
  2298. * double x, y, y1l();
  2299. *
  2300. * y = y1l( x );
  2301. *
  2302. *
  2303. *
  2304. * DESCRIPTION:
  2305. *
  2306. * Returns Bessel function of the second kind, of order
  2307. * zero, of the argument.
  2308. *
  2309. * The domain is divided into the intervals [0, 4.5>, [4.5,9> and
  2310. * [9, infinity). In the first interval a rational approximation
  2311. * R(x) is employed to compute y0(x) = R(x) + 2/pi * log(x) * j0(x).
  2312. *
  2313. * In the second interval, the approximation is
  2314. * (x - p)(x - q)(x - r)(x - s)P9(x)/Q10(x)
  2315. * where p, q, r, s are zeros of y1(x).
  2316. *
  2317. * The third interval uses the same approximations to modulus
  2318. * and phase as j1(x), whence y1(x) = modulus * sin(phase).
  2319. *
  2320. * ACCURACY:
  2321. *
  2322. * Absolute error, when y0(x) < 1; else relative error:
  2323. *
  2324. * arithmetic domain # trials peak rms
  2325. * IEEE 0, 30 36000 2.7e-19 5.3e-20
  2326. *
  2327. */
  2328. /* jnl.c
  2329. *
  2330. * Bessel function of integer order
  2331. *
  2332. *
  2333. *
  2334. * SYNOPSIS:
  2335. *
  2336. * int n;
  2337. * long double x, y, jnl();
  2338. *
  2339. * y = jnl( n, x );
  2340. *
  2341. *
  2342. *
  2343. * DESCRIPTION:
  2344. *
  2345. * Returns Bessel function of order n, where n is a
  2346. * (possibly negative) integer.
  2347. *
  2348. * The ratio of jn(x) to j0(x) is computed by backward
  2349. * recurrence. First the ratio jn/jn-1 is found by a
  2350. * continued fraction expansion. Then the recurrence
  2351. * relating successive orders is applied until j0 or j1 is
  2352. * reached.
  2353. *
  2354. * If n = 0 or 1 the routine for j0 or j1 is called
  2355. * directly.
  2356. *
  2357. *
  2358. *
  2359. * ACCURACY:
  2360. *
  2361. * Absolute error:
  2362. * arithmetic domain # trials peak rms
  2363. * IEEE -30, 30 5000 3.3e-19 4.7e-20
  2364. *
  2365. *
  2366. * Not suitable for large n or x.
  2367. *
  2368. */
  2369. /* ldrand.c
  2370. *
  2371. * Pseudorandom number generator
  2372. *
  2373. *
  2374. *
  2375. * SYNOPSIS:
  2376. *
  2377. * double y;
  2378. * int ldrand();
  2379. *
  2380. * ldrand( &y );
  2381. *
  2382. *
  2383. *
  2384. * DESCRIPTION:
  2385. *
  2386. * Yields a random number 1.0 <= y < 2.0.
  2387. *
  2388. * The three-generator congruential algorithm by Brian
  2389. * Wichmann and David Hill (BYTE magazine, March, 1987,
  2390. * pp 127-8) is used.
  2391. *
  2392. * Versions invoked by the different arithmetic compile
  2393. * time options IBMPC, and MIEEE, produce the same sequences.
  2394. *
  2395. */
  2396. /* log10l.c
  2397. *
  2398. * Common logarithm, long double precision
  2399. *
  2400. *
  2401. *
  2402. * SYNOPSIS:
  2403. *
  2404. * long double x, y, log10l();
  2405. *
  2406. * y = log10l( x );
  2407. *
  2408. *
  2409. *
  2410. * DESCRIPTION:
  2411. *
  2412. * Returns the base 10 logarithm of x.
  2413. *
  2414. * The argument is separated into its exponent and fractional
  2415. * parts. If the exponent is between -1 and +1, the logarithm
  2416. * of the fraction is approximated by
  2417. *
  2418. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  2419. *
  2420. * Otherwise, setting z = 2(x-1)/x+1),
  2421. *
  2422. * log(x) = z + z**3 P(z)/Q(z).
  2423. *
  2424. *
  2425. *
  2426. * ACCURACY:
  2427. *
  2428. * Relative error:
  2429. * arithmetic domain # trials peak rms
  2430. * IEEE 0.5, 2.0 30000 9.0e-20 2.6e-20
  2431. * IEEE exp(+-10000) 30000 6.0e-20 2.3e-20
  2432. *
  2433. * In the tests over the interval exp(+-10000), the logarithms
  2434. * of the random arguments were uniformly distributed over
  2435. * [-10000, +10000].
  2436. *
  2437. * ERROR MESSAGES:
  2438. *
  2439. * log singularity: x = 0; returns MINLOG
  2440. * log domain: x < 0; returns MINLOG
  2441. */
  2442. /* log2l.c
  2443. *
  2444. * Base 2 logarithm, long double precision
  2445. *
  2446. *
  2447. *
  2448. * SYNOPSIS:
  2449. *
  2450. * long double x, y, log2l();
  2451. *
  2452. * y = log2l( x );
  2453. *
  2454. *
  2455. *
  2456. * DESCRIPTION:
  2457. *
  2458. * Returns the base 2 logarithm of x.
  2459. *
  2460. * The argument is separated into its exponent and fractional
  2461. * parts. If the exponent is between -1 and +1, the (natural)
  2462. * logarithm of the fraction is approximated by
  2463. *
  2464. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  2465. *
  2466. * Otherwise, setting z = 2(x-1)/x+1),
  2467. *
  2468. * log(x) = z + z**3 P(z)/Q(z).
  2469. *
  2470. *
  2471. *
  2472. * ACCURACY:
  2473. *
  2474. * Relative error:
  2475. * arithmetic domain # trials peak rms
  2476. * IEEE 0.5, 2.0 30000 9.8e-20 2.7e-20
  2477. * IEEE exp(+-10000) 70000 5.4e-20 2.3e-20
  2478. *
  2479. * In the tests over the interval exp(+-10000), the logarithms
  2480. * of the random arguments were uniformly distributed over
  2481. * [-10000, +10000].
  2482. *
  2483. * ERROR MESSAGES:
  2484. *
  2485. * log singularity: x = 0; returns MINLOG
  2486. * log domain: x < 0; returns MINLOG
  2487. */
  2488. /* logl.c
  2489. *
  2490. * Natural logarithm, long double precision
  2491. *
  2492. *
  2493. *
  2494. * SYNOPSIS:
  2495. *
  2496. * long double x, y, logl();
  2497. *
  2498. * y = logl( x );
  2499. *
  2500. *
  2501. *
  2502. * DESCRIPTION:
  2503. *
  2504. * Returns the base e (2.718...) logarithm of x.
  2505. *
  2506. * The argument is separated into its exponent and fractional
  2507. * parts. If the exponent is between -1 and +1, the logarithm
  2508. * of the fraction is approximated by
  2509. *
  2510. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  2511. *
  2512. * Otherwise, setting z = 2(x-1)/x+1),
  2513. *
  2514. * log(x) = z + z**3 P(z)/Q(z).
  2515. *
  2516. *
  2517. *
  2518. * ACCURACY:
  2519. *
  2520. * Relative error:
  2521. * arithmetic domain # trials peak rms
  2522. * IEEE 0.5, 2.0 150000 8.71e-20 2.75e-20
  2523. * IEEE exp(+-10000) 100000 5.39e-20 2.34e-20
  2524. *
  2525. * In the tests over the interval exp(+-10000), the logarithms
  2526. * of the random arguments were uniformly distributed over
  2527. * [-10000, +10000].
  2528. *
  2529. * ERROR MESSAGES:
  2530. *
  2531. * log singularity: x = 0; returns MINLOG
  2532. * log domain: x < 0; returns MINLOG
  2533. */
  2534. /* mtherr.c
  2535. *
  2536. * Library common error handling routine
  2537. *
  2538. *
  2539. *
  2540. * SYNOPSIS:
  2541. *
  2542. * char *fctnam;
  2543. * int code;
  2544. * int mtherr();
  2545. *
  2546. * mtherr( fctnam, code );
  2547. *
  2548. *
  2549. *
  2550. * DESCRIPTION:
  2551. *
  2552. * This routine may be called to report one of the following
  2553. * error conditions (in the include file mconf.h).
  2554. *
  2555. * Mnemonic Value Significance
  2556. *
  2557. * DOMAIN 1 argument domain error
  2558. * SING 2 function singularity
  2559. * OVERFLOW 3 overflow range error
  2560. * UNDERFLOW 4 underflow range error
  2561. * TLOSS 5 total loss of precision
  2562. * PLOSS 6 partial loss of precision
  2563. * EDOM 33 Unix domain error code
  2564. * ERANGE 34 Unix range error code
  2565. *
  2566. * The default version of the file prints the function name,
  2567. * passed to it by the pointer fctnam, followed by the
  2568. * error condition. The display is directed to the standard
  2569. * output device. The routine then returns to the calling
  2570. * program. Users may wish to modify the program to abort by
  2571. * calling exit() under severe error conditions such as domain
  2572. * errors.
  2573. *
  2574. * Since all error conditions pass control to this function,
  2575. * the display may be easily changed, eliminated, or directed
  2576. * to an error logging device.
  2577. *
  2578. * SEE ALSO:
  2579. *
  2580. * mconf.h
  2581. *
  2582. */
  2583. /* nbdtrl.c
  2584. *
  2585. * Negative binomial distribution
  2586. *
  2587. *
  2588. *
  2589. * SYNOPSIS:
  2590. *
  2591. * int k, n;
  2592. * long double p, y, nbdtrl();
  2593. *
  2594. * y = nbdtrl( k, n, p );
  2595. *
  2596. *
  2597. *
  2598. * DESCRIPTION:
  2599. *
  2600. * Returns the sum of the terms 0 through k of the negative
  2601. * binomial distribution:
  2602. *
  2603. * k
  2604. * -- ( n+j-1 ) n j
  2605. * > ( ) p (1-p)
  2606. * -- ( j )
  2607. * j=0
  2608. *
  2609. * In a sequence of Bernoulli trials, this is the probability
  2610. * that k or fewer failures precede the nth success.
  2611. *
  2612. * The terms are not computed individually; instead the incomplete
  2613. * beta integral is employed, according to the formula
  2614. *
  2615. * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
  2616. *
  2617. * The arguments must be positive, with p ranging from 0 to 1.
  2618. *
  2619. *
  2620. *
  2621. * ACCURACY:
  2622. *
  2623. * Tested at random points (k,n,p) with k and n between 1 and 10,000
  2624. * and p between 0 and 1.
  2625. *
  2626. * arithmetic domain # trials peak rms
  2627. * Absolute error:
  2628. * IEEE 0,10000 10000 9.8e-15 2.1e-16
  2629. *
  2630. */
  2631. /* nbdtrcl.c
  2632. *
  2633. * Complemented negative binomial distribution
  2634. *
  2635. *
  2636. *
  2637. * SYNOPSIS:
  2638. *
  2639. * int k, n;
  2640. * long double p, y, nbdtrcl();
  2641. *
  2642. * y = nbdtrcl( k, n, p );
  2643. *
  2644. *
  2645. *
  2646. * DESCRIPTION:
  2647. *
  2648. * Returns the sum of the terms k+1 to infinity of the negative
  2649. * binomial distribution:
  2650. *
  2651. * inf
  2652. * -- ( n+j-1 ) n j
  2653. * > ( ) p (1-p)
  2654. * -- ( j )
  2655. * j=k+1
  2656. *
  2657. * The terms are not computed individually; instead the incomplete
  2658. * beta integral is employed, according to the formula
  2659. *
  2660. * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
  2661. *
  2662. * The arguments must be positive, with p ranging from 0 to 1.
  2663. *
  2664. *
  2665. *
  2666. * ACCURACY:
  2667. *
  2668. * See incbetl.c.
  2669. *
  2670. */
  2671. /* nbdtril
  2672. *
  2673. * Functional inverse of negative binomial distribution
  2674. *
  2675. *
  2676. *
  2677. * SYNOPSIS:
  2678. *
  2679. * int k, n;
  2680. * long double p, y, nbdtril();
  2681. *
  2682. * p = nbdtril( k, n, y );
  2683. *
  2684. *
  2685. *
  2686. * DESCRIPTION:
  2687. *
  2688. * Finds the argument p such that nbdtr(k,n,p) is equal to y.
  2689. *
  2690. * ACCURACY:
  2691. *
  2692. * Tested at random points (a,b,y), with y between 0 and 1.
  2693. *
  2694. * a,b Relative error:
  2695. * arithmetic domain # trials peak rms
  2696. * IEEE 0,100
  2697. * See also incbil.c.
  2698. */
  2699. /* ndtril.c
  2700. *
  2701. * Inverse of Normal distribution function
  2702. *
  2703. *
  2704. *
  2705. * SYNOPSIS:
  2706. *
  2707. * long double x, y, ndtril();
  2708. *
  2709. * x = ndtril( y );
  2710. *
  2711. *
  2712. *
  2713. * DESCRIPTION:
  2714. *
  2715. * Returns the argument, x, for which the area under the
  2716. * Gaussian probability density function (integrated from
  2717. * minus infinity to x) is equal to y.
  2718. *
  2719. *
  2720. * For small arguments 0 < y < exp(-2), the program computes
  2721. * z = sqrt( -2 log(y) ); then the approximation is
  2722. * x = z - log(z)/z - (1/z) P(1/z) / Q(1/z) .
  2723. * For larger arguments, x/sqrt(2 pi) = w + w^3 R(w^2)/S(w^2)) ,
  2724. * where w = y - 0.5 .
  2725. *
  2726. * ACCURACY:
  2727. *
  2728. * Relative error:
  2729. * arithmetic domain # trials peak rms
  2730. * Arguments uniformly distributed:
  2731. * IEEE 0, 1 5000 7.8e-19 9.9e-20
  2732. * Arguments exponentially distributed:
  2733. * IEEE exp(-11355),-1 30000 1.7e-19 4.3e-20
  2734. *
  2735. *
  2736. * ERROR MESSAGES:
  2737. *
  2738. * message condition value returned
  2739. * ndtril domain x <= 0 -MAXNUML
  2740. * ndtril domain x >= 1 MAXNUML
  2741. *
  2742. */
  2743. /* ndtril.c
  2744. *
  2745. * Inverse of Normal distribution function
  2746. *
  2747. *
  2748. *
  2749. * SYNOPSIS:
  2750. *
  2751. * long double x, y, ndtril();
  2752. *
  2753. * x = ndtril( y );
  2754. *
  2755. *
  2756. *
  2757. * DESCRIPTION:
  2758. *
  2759. * Returns the argument, x, for which the area under the
  2760. * Gaussian probability density function (integrated from
  2761. * minus infinity to x) is equal to y.
  2762. *
  2763. *
  2764. * For small arguments 0 < y < exp(-2), the program computes
  2765. * z = sqrt( -2 log(y) ); then the approximation is
  2766. * x = z - log(z)/z - (1/z) P(1/z) / Q(1/z) .
  2767. * For larger arguments, x/sqrt(2 pi) = w + w^3 R(w^2)/S(w^2)) ,
  2768. * where w = y - 0.5 .
  2769. *
  2770. * ACCURACY:
  2771. *
  2772. * Relative error:
  2773. * arithmetic domain # trials peak rms
  2774. * Arguments uniformly distributed:
  2775. * IEEE 0, 1 5000 7.8e-19 9.9e-20
  2776. * Arguments exponentially distributed:
  2777. * IEEE exp(-11355),-1 30000 1.7e-19 4.3e-20
  2778. *
  2779. *
  2780. * ERROR MESSAGES:
  2781. *
  2782. * message condition value returned
  2783. * ndtril domain x <= 0 -MAXNUML
  2784. * ndtril domain x >= 1 MAXNUML
  2785. *
  2786. */
  2787. /* pdtrl.c
  2788. *
  2789. * Poisson distribution
  2790. *
  2791. *
  2792. *
  2793. * SYNOPSIS:
  2794. *
  2795. * int k;
  2796. * long double m, y, pdtrl();
  2797. *
  2798. * y = pdtrl( k, m );
  2799. *
  2800. *
  2801. *
  2802. * DESCRIPTION:
  2803. *
  2804. * Returns the sum of the first k terms of the Poisson
  2805. * distribution:
  2806. *
  2807. * k j
  2808. * -- -m m
  2809. * > e --
  2810. * -- j!
  2811. * j=0
  2812. *
  2813. * The terms are not summed directly; instead the incomplete
  2814. * gamma integral is employed, according to the relation
  2815. *
  2816. * y = pdtr( k, m ) = igamc( k+1, m ).
  2817. *
  2818. * The arguments must both be positive.
  2819. *
  2820. *
  2821. *
  2822. * ACCURACY:
  2823. *
  2824. * See igamc().
  2825. *
  2826. */
  2827. /* pdtrcl()
  2828. *
  2829. * Complemented poisson distribution
  2830. *
  2831. *
  2832. *
  2833. * SYNOPSIS:
  2834. *
  2835. * int k;
  2836. * long double m, y, pdtrcl();
  2837. *
  2838. * y = pdtrcl( k, m );
  2839. *
  2840. *
  2841. *
  2842. * DESCRIPTION:
  2843. *
  2844. * Returns the sum of the terms k+1 to infinity of the Poisson
  2845. * distribution:
  2846. *
  2847. * inf. j
  2848. * -- -m m
  2849. * > e --
  2850. * -- j!
  2851. * j=k+1
  2852. *
  2853. * The terms are not summed directly; instead the incomplete
  2854. * gamma integral is employed, according to the formula
  2855. *
  2856. * y = pdtrc( k, m ) = igam( k+1, m ).
  2857. *
  2858. * The arguments must both be positive.
  2859. *
  2860. *
  2861. *
  2862. * ACCURACY:
  2863. *
  2864. * See igam.c.
  2865. *
  2866. */
  2867. /* pdtril()
  2868. *
  2869. * Inverse Poisson distribution
  2870. *
  2871. *
  2872. *
  2873. * SYNOPSIS:
  2874. *
  2875. * int k;
  2876. * long double m, y, pdtrl();
  2877. *
  2878. * m = pdtril( k, y );
  2879. *
  2880. *
  2881. *
  2882. *
  2883. * DESCRIPTION:
  2884. *
  2885. * Finds the Poisson variable x such that the integral
  2886. * from 0 to x of the Poisson density is equal to the
  2887. * given probability y.
  2888. *
  2889. * This is accomplished using the inverse gamma integral
  2890. * function and the relation
  2891. *
  2892. * m = igami( k+1, y ).
  2893. *
  2894. *
  2895. *
  2896. *
  2897. * ACCURACY:
  2898. *
  2899. * See igami.c.
  2900. *
  2901. * ERROR MESSAGES:
  2902. *
  2903. * message condition value returned
  2904. * pdtri domain y < 0 or y >= 1 0.0
  2905. * k < 0
  2906. *
  2907. */
  2908. /* polevll.c
  2909. * p1evll.c
  2910. *
  2911. * Evaluate polynomial
  2912. *
  2913. *
  2914. *
  2915. * SYNOPSIS:
  2916. *
  2917. * int N;
  2918. * long double x, y, coef[N+1], polevl[];
  2919. *
  2920. * y = polevll( x, coef, N );
  2921. *
  2922. *
  2923. *
  2924. * DESCRIPTION:
  2925. *
  2926. * Evaluates polynomial of degree N:
  2927. *
  2928. * 2 N
  2929. * y = C + C x + C x +...+ C x
  2930. * 0 1 2 N
  2931. *
  2932. * Coefficients are stored in reverse order:
  2933. *
  2934. * coef[0] = C , ..., coef[N] = C .
  2935. * N 0
  2936. *
  2937. * The function p1evll() assumes that coef[N] = 1.0 and is
  2938. * omitted from the array. Its calling arguments are
  2939. * otherwise the same as polevll().
  2940. *
  2941. * This module also contains the following globally declared constants:
  2942. * MAXNUML = 1.189731495357231765021263853E4932L;
  2943. * MACHEPL = 5.42101086242752217003726400434970855712890625E-20L;
  2944. * MAXLOGL = 1.1356523406294143949492E4L;
  2945. * MINLOGL = -1.1355137111933024058873E4L;
  2946. * LOGE2L = 6.9314718055994530941723E-1L;
  2947. * LOG2EL = 1.4426950408889634073599E0L;
  2948. * PIL = 3.1415926535897932384626L;
  2949. * PIO2L = 1.5707963267948966192313L;
  2950. * PIO4L = 7.8539816339744830961566E-1L;
  2951. *
  2952. * SPEED:
  2953. *
  2954. * In the interest of speed, there are no checks for out
  2955. * of bounds arithmetic. This routine is used by most of
  2956. * the functions in the library. Depending on available
  2957. * equipment features, the user may wish to rewrite the
  2958. * program in microcode or assembly language.
  2959. *
  2960. */
  2961. /* powil.c
  2962. *
  2963. * Real raised to integer power, long double precision
  2964. *
  2965. *
  2966. *
  2967. * SYNOPSIS:
  2968. *
  2969. * long double x, y, powil();
  2970. * int n;
  2971. *
  2972. * y = powil( x, n );
  2973. *
  2974. *
  2975. *
  2976. * DESCRIPTION:
  2977. *
  2978. * Returns argument x raised to the nth power.
  2979. * The routine efficiently decomposes n as a sum of powers of
  2980. * two. The desired power is a product of two-to-the-kth
  2981. * powers of x. Thus to compute the 32767 power of x requires
  2982. * 28 multiplications instead of 32767 multiplications.
  2983. *
  2984. *
  2985. *
  2986. * ACCURACY:
  2987. *
  2988. *
  2989. * Relative error:
  2990. * arithmetic x domain n domain # trials peak rms
  2991. * IEEE .001,1000 -1022,1023 50000 4.3e-17 7.8e-18
  2992. * IEEE 1,2 -1022,1023 20000 3.9e-17 7.6e-18
  2993. * IEEE .99,1.01 0,8700 10000 3.6e-16 7.2e-17
  2994. *
  2995. * Returns MAXNUM on overflow, zero on underflow.
  2996. *
  2997. */
  2998. /* powl.c
  2999. *
  3000. * Power function, long double precision
  3001. *
  3002. *
  3003. *
  3004. * SYNOPSIS:
  3005. *
  3006. * long double x, y, z, powl();
  3007. *
  3008. * z = powl( x, y );
  3009. *
  3010. *
  3011. *
  3012. * DESCRIPTION:
  3013. *
  3014. * Computes x raised to the yth power. Analytically,
  3015. *
  3016. * x**y = exp( y log(x) ).
  3017. *
  3018. * Following Cody and Waite, this program uses a lookup table
  3019. * of 2**-i/32 and pseudo extended precision arithmetic to
  3020. * obtain several extra bits of accuracy in both the logarithm
  3021. * and the exponential.
  3022. *
  3023. *
  3024. *
  3025. * ACCURACY:
  3026. *
  3027. * The relative error of pow(x,y) can be estimated
  3028. * by y dl ln(2), where dl is the absolute error of
  3029. * the internally computed base 2 logarithm. At the ends
  3030. * of the approximation interval the logarithm equal 1/32
  3031. * and its relative error is about 1 lsb = 1.1e-19. Hence
  3032. * the predicted relative error in the result is 2.3e-21 y .
  3033. *
  3034. * Relative error:
  3035. * arithmetic domain # trials peak rms
  3036. *
  3037. * IEEE +-1000 40000 2.8e-18 3.7e-19
  3038. * .001 < x < 1000, with log(x) uniformly distributed.
  3039. * -1000 < y < 1000, y uniformly distributed.
  3040. *
  3041. * IEEE 0,8700 60000 6.5e-18 1.0e-18
  3042. * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed.
  3043. *
  3044. *
  3045. * ERROR MESSAGES:
  3046. *
  3047. * message condition value returned
  3048. * pow overflow x**y > MAXNUM MAXNUM
  3049. * pow underflow x**y < 1/MAXNUM 0.0
  3050. * pow domain x<0 and y noninteger 0.0
  3051. *
  3052. */
  3053. /* sinhl.c
  3054. *
  3055. * Hyperbolic sine, long double precision
  3056. *
  3057. *
  3058. *
  3059. * SYNOPSIS:
  3060. *
  3061. * long double x, y, sinhl();
  3062. *
  3063. * y = sinhl( x );
  3064. *
  3065. *
  3066. *
  3067. * DESCRIPTION:
  3068. *
  3069. * Returns hyperbolic sine of argument in the range MINLOGL to
  3070. * MAXLOGL.
  3071. *
  3072. * The range is partitioned into two segments. If |x| <= 1, a
  3073. * rational function of the form x + x**3 P(x)/Q(x) is employed.
  3074. * Otherwise the calculation is sinh(x) = ( exp(x) - exp(-x) )/2.
  3075. *
  3076. *
  3077. *
  3078. * ACCURACY:
  3079. *
  3080. * Relative error:
  3081. * arithmetic domain # trials peak rms
  3082. * IEEE -2,2 10000 1.5e-19 3.9e-20
  3083. * IEEE +-10000 30000 1.1e-19 2.8e-20
  3084. *
  3085. */
  3086. /* sinl.c
  3087. *
  3088. * Circular sine, long double precision
  3089. *
  3090. *
  3091. *
  3092. * SYNOPSIS:
  3093. *
  3094. * long double x, y, sinl();
  3095. *
  3096. * y = sinl( x );
  3097. *
  3098. *
  3099. *
  3100. * DESCRIPTION:
  3101. *
  3102. * Range reduction is into intervals of pi/4. The reduction
  3103. * error is nearly eliminated by contriving an extended precision
  3104. * modular arithmetic.
  3105. *
  3106. * Two polynomial approximating functions are employed.
  3107. * Between 0 and pi/4 the sine is approximated by the Cody
  3108. * and Waite polynomial form
  3109. * x + x**3 P(x**2) .
  3110. * Between pi/4 and pi/2 the cosine is represented as
  3111. * 1 - .5 x**2 + x**4 Q(x**2) .
  3112. *
  3113. *
  3114. * ACCURACY:
  3115. *
  3116. * Relative error:
  3117. * arithmetic domain # trials peak rms
  3118. * IEEE +-5.5e11 200,000 1.2e-19 2.9e-20
  3119. *
  3120. * ERROR MESSAGES:
  3121. *
  3122. * message condition value returned
  3123. * sin total loss x > 2**39 0.0
  3124. *
  3125. * Loss of precision occurs for x > 2**39 = 5.49755813888e11.
  3126. * The routine as implemented flags a TLOSS error for
  3127. * x > 2**39 and returns 0.0.
  3128. */
  3129. /* cosl.c
  3130. *
  3131. * Circular cosine, long double precision
  3132. *
  3133. *
  3134. *
  3135. * SYNOPSIS:
  3136. *
  3137. * long double x, y, cosl();
  3138. *
  3139. * y = cosl( x );
  3140. *
  3141. *
  3142. *
  3143. * DESCRIPTION:
  3144. *
  3145. * Range reduction is into intervals of pi/4. The reduction
  3146. * error is nearly eliminated by contriving an extended precision
  3147. * modular arithmetic.
  3148. *
  3149. * Two polynomial approximating functions are employed.
  3150. * Between 0 and pi/4 the cosine is approximated by
  3151. * 1 - .5 x**2 + x**4 Q(x**2) .
  3152. * Between pi/4 and pi/2 the sine is represented by the Cody
  3153. * and Waite polynomial form
  3154. * x + x**3 P(x**2) .
  3155. *
  3156. *
  3157. * ACCURACY:
  3158. *
  3159. * Relative error:
  3160. * arithmetic domain # trials peak rms
  3161. * IEEE +-5.5e11 50000 1.2e-19 2.9e-20
  3162. */
  3163. /* sqrtl.c
  3164. *
  3165. * Square root, long double precision
  3166. *
  3167. *
  3168. *
  3169. * SYNOPSIS:
  3170. *
  3171. * long double x, y, sqrtl();
  3172. *
  3173. * y = sqrtl( x );
  3174. *
  3175. *
  3176. *
  3177. * DESCRIPTION:
  3178. *
  3179. * Returns the square root of x.
  3180. *
  3181. * Range reduction involves isolating the power of two of the
  3182. * argument and using a polynomial approximation to obtain
  3183. * a rough value for the square root. Then Heron's iteration
  3184. * is used three times to converge to an accurate value.
  3185. *
  3186. * Note, some arithmetic coprocessors such as the 8087 and
  3187. * 68881 produce correctly rounded square roots, which this
  3188. * routine will not.
  3189. *
  3190. * ACCURACY:
  3191. *
  3192. *
  3193. * Relative error:
  3194. * arithmetic domain # trials peak rms
  3195. * IEEE 0,10 30000 8.1e-20 3.1e-20
  3196. *
  3197. *
  3198. * ERROR MESSAGES:
  3199. *
  3200. * message condition value returned
  3201. * sqrt domain x < 0 0.0
  3202. *
  3203. */
  3204. /* stdtrl.c
  3205. *
  3206. * Student's t distribution
  3207. *
  3208. *
  3209. *
  3210. * SYNOPSIS:
  3211. *
  3212. * long double p, t, stdtrl();
  3213. * int k;
  3214. *
  3215. * p = stdtrl( k, t );
  3216. *
  3217. *
  3218. * DESCRIPTION:
  3219. *
  3220. * Computes the integral from minus infinity to t of the Student
  3221. * t distribution with integer k > 0 degrees of freedom:
  3222. *
  3223. * t
  3224. * -
  3225. * | |
  3226. * - | 2 -(k+1)/2
  3227. * | ( (k+1)/2 ) | ( x )
  3228. * ---------------------- | ( 1 + --- ) dx
  3229. * - | ( k )
  3230. * sqrt( k pi ) | ( k/2 ) |
  3231. * | |
  3232. * -
  3233. * -inf.
  3234. *
  3235. * Relation to incomplete beta integral:
  3236. *
  3237. * 1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )
  3238. * where
  3239. * z = k/(k + t**2).
  3240. *
  3241. * For t < -1.6, this is the method of computation. For higher t,
  3242. * a direct method is derived from integration by parts.
  3243. * Since the function is symmetric about t=0, the area under the
  3244. * right tail of the density is found by calling the function
  3245. * with -t instead of t.
  3246. *
  3247. * ACCURACY:
  3248. *
  3249. * Tested at random 1 <= k <= 100. The "domain" refers to t.
  3250. * Relative error:
  3251. * arithmetic domain # trials peak rms
  3252. * IEEE -100,-1.6 10000 5.7e-18 9.8e-19
  3253. * IEEE -1.6,100 10000 3.8e-18 1.0e-19
  3254. */
  3255. /* stdtril.c
  3256. *
  3257. * Functional inverse of Student's t distribution
  3258. *
  3259. *
  3260. *
  3261. * SYNOPSIS:
  3262. *
  3263. * long double p, t, stdtril();
  3264. * int k;
  3265. *
  3266. * t = stdtril( k, p );
  3267. *
  3268. *
  3269. * DESCRIPTION:
  3270. *
  3271. * Given probability p, finds the argument t such that stdtrl(k,t)
  3272. * is equal to p.
  3273. *
  3274. * ACCURACY:
  3275. *
  3276. * Tested at random 1 <= k <= 100. The "domain" refers to p:
  3277. * Relative error:
  3278. * arithmetic domain # trials peak rms
  3279. * IEEE 0,1 3500 4.2e-17 4.1e-18
  3280. */
  3281. /* tanhl.c
  3282. *
  3283. * Hyperbolic tangent, long double precision
  3284. *
  3285. *
  3286. *
  3287. * SYNOPSIS:
  3288. *
  3289. * long double x, y, tanhl();
  3290. *
  3291. * y = tanhl( x );
  3292. *
  3293. *
  3294. *
  3295. * DESCRIPTION:
  3296. *
  3297. * Returns hyperbolic tangent of argument in the range MINLOGL to
  3298. * MAXLOGL.
  3299. *
  3300. * A rational function is used for |x| < 0.625. The form
  3301. * x + x**3 P(x)/Q(x) of Cody _& Waite is employed.
  3302. * Otherwise,
  3303. * tanh(x) = sinh(x)/cosh(x) = 1 - 2/(exp(2x) + 1).
  3304. *
  3305. *
  3306. *
  3307. * ACCURACY:
  3308. *
  3309. * Relative error:
  3310. * arithmetic domain # trials peak rms
  3311. * IEEE -2,2 30000 1.3e-19 2.4e-20
  3312. *
  3313. */
  3314. /* tanl.c
  3315. *
  3316. * Circular tangent, long double precision
  3317. *
  3318. *
  3319. *
  3320. * SYNOPSIS:
  3321. *
  3322. * long double x, y, tanl();
  3323. *
  3324. * y = tanl( x );
  3325. *
  3326. *
  3327. *
  3328. * DESCRIPTION:
  3329. *
  3330. * Returns the circular tangent of the radian argument x.
  3331. *
  3332. * Range reduction is modulo pi/4. A rational function
  3333. * x + x**3 P(x**2)/Q(x**2)
  3334. * is employed in the basic interval [0, pi/4].
  3335. *
  3336. *
  3337. *
  3338. * ACCURACY:
  3339. *
  3340. * Relative error:
  3341. * arithmetic domain # trials peak rms
  3342. * IEEE +-1.07e9 30000 1.9e-19 4.8e-20
  3343. *
  3344. * ERROR MESSAGES:
  3345. *
  3346. * message condition value returned
  3347. * tan total loss x > 2^39 0.0
  3348. *
  3349. */
  3350. /* cotl.c
  3351. *
  3352. * Circular cotangent, long double precision
  3353. *
  3354. *
  3355. *
  3356. * SYNOPSIS:
  3357. *
  3358. * long double x, y, cotl();
  3359. *
  3360. * y = cotl( x );
  3361. *
  3362. *
  3363. *
  3364. * DESCRIPTION:
  3365. *
  3366. * Returns the circular cotangent of the radian argument x.
  3367. *
  3368. * Range reduction is modulo pi/4. A rational function
  3369. * x + x**3 P(x**2)/Q(x**2)
  3370. * is employed in the basic interval [0, pi/4].
  3371. *
  3372. *
  3373. *
  3374. * ACCURACY:
  3375. *
  3376. * Relative error:
  3377. * arithmetic domain # trials peak rms
  3378. * IEEE +-1.07e9 30000 1.9e-19 5.1e-20
  3379. *
  3380. *
  3381. * ERROR MESSAGES:
  3382. *
  3383. * message condition value returned
  3384. * cot total loss x > 2^39 0.0
  3385. * cot singularity x = 0 MAXNUM
  3386. *
  3387. */
  3388. /* unityl.c
  3389. *
  3390. * Relative error approximations for function arguments near
  3391. * unity.
  3392. *
  3393. * log1p(x) = log(1+x)
  3394. * expm1(x) = exp(x) - 1
  3395. * cos1m(x) = cos(x) - 1
  3396. *
  3397. */
  3398. /* ynl.c
  3399. *
  3400. * Bessel function of second kind of integer order
  3401. *
  3402. *
  3403. *
  3404. * SYNOPSIS:
  3405. *
  3406. * long double x, y, ynl();
  3407. * int n;
  3408. *
  3409. * y = ynl( n, x );
  3410. *
  3411. *
  3412. *
  3413. * DESCRIPTION:
  3414. *
  3415. * Returns Bessel function of order n, where n is a
  3416. * (possibly negative) integer.
  3417. *
  3418. * The function is evaluated by forward recurrence on
  3419. * n, starting with values computed by the routines
  3420. * y0l() and y1l().
  3421. *
  3422. * If n = 0 or 1 the routine for y0l or y1l is called
  3423. * directly.
  3424. *
  3425. *
  3426. *
  3427. * ACCURACY:
  3428. *
  3429. *
  3430. * Absolute error, except relative error when y > 1.
  3431. * x >= 0, -30 <= n <= +30.
  3432. * arithmetic domain # trials peak rms
  3433. * IEEE -30, 30 10000 1.3e-18 1.8e-19
  3434. *
  3435. *
  3436. * ERROR MESSAGES:
  3437. *
  3438. * message condition value returned
  3439. * ynl singularity x = 0 MAXNUML
  3440. * ynl overflow MAXNUML
  3441. *
  3442. * Spot checked against tables for x, n between 0 and 100.
  3443. *
  3444. */