README.txt 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845
  1. /* acosh.c
  2. *
  3. * Inverse hyperbolic cosine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, acosh();
  10. *
  11. * y = acosh( 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(z) * 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. * DEC 1,3 30000 4.2e-17 1.1e-17
  34. * IEEE 1,3 30000 4.6e-16 8.7e-17
  35. *
  36. *
  37. * ERROR MESSAGES:
  38. *
  39. * message condition value returned
  40. * acosh domain |x| < 1 NAN
  41. *
  42. */
  43. /* airy.c
  44. *
  45. * Airy function
  46. *
  47. *
  48. *
  49. * SYNOPSIS:
  50. *
  51. * double x, ai, aip, bi, bip;
  52. * int airy();
  53. *
  54. * airy( x, _&ai, _&aip, _&bi, _&bip );
  55. *
  56. *
  57. *
  58. * DESCRIPTION:
  59. *
  60. * Solution of the differential equation
  61. *
  62. * y"(x) = xy.
  63. *
  64. * The function returns the two independent solutions Ai, Bi
  65. * and their first derivatives Ai'(x), Bi'(x).
  66. *
  67. * Evaluation is by power series summation for small x,
  68. * by rational minimax approximations for large x.
  69. *
  70. *
  71. *
  72. * ACCURACY:
  73. * Error criterion is absolute when function <= 1, relative
  74. * when function > 1, except * denotes relative error criterion.
  75. * For large negative x, the absolute error increases as x^1.5.
  76. * For large positive x, the relative error increases as x^1.5.
  77. *
  78. * Arithmetic domain function # trials peak rms
  79. * IEEE -10, 0 Ai 10000 1.6e-15 2.7e-16
  80. * IEEE 0, 10 Ai 10000 2.3e-14* 1.8e-15*
  81. * IEEE -10, 0 Ai' 10000 4.6e-15 7.6e-16
  82. * IEEE 0, 10 Ai' 10000 1.8e-14* 1.5e-15*
  83. * IEEE -10, 10 Bi 30000 4.2e-15 5.3e-16
  84. * IEEE -10, 10 Bi' 30000 4.9e-15 7.3e-16
  85. * DEC -10, 0 Ai 5000 1.7e-16 2.8e-17
  86. * DEC 0, 10 Ai 5000 2.1e-15* 1.7e-16*
  87. * DEC -10, 0 Ai' 5000 4.7e-16 7.8e-17
  88. * DEC 0, 10 Ai' 12000 1.8e-15* 1.5e-16*
  89. * DEC -10, 10 Bi 10000 5.5e-16 6.8e-17
  90. * DEC -10, 10 Bi' 7000 5.3e-16 8.7e-17
  91. *
  92. */
  93. /* asin.c
  94. *
  95. * Inverse circular sine
  96. *
  97. *
  98. *
  99. * SYNOPSIS:
  100. *
  101. * double x, y, asin();
  102. *
  103. * y = asin( x );
  104. *
  105. *
  106. *
  107. * DESCRIPTION:
  108. *
  109. * Returns radian angle between -pi/2 and +pi/2 whose sine is x.
  110. *
  111. * A rational function of the form x + x**3 P(x**2)/Q(x**2)
  112. * is used for |x| in the interval [0, 0.5]. If |x| > 0.5 it is
  113. * transformed by the identity
  114. *
  115. * asin(x) = pi/2 - 2 asin( sqrt( (1-x)/2 ) ).
  116. *
  117. *
  118. * ACCURACY:
  119. *
  120. * Relative error:
  121. * arithmetic domain # trials peak rms
  122. * DEC -1, 1 40000 2.6e-17 7.1e-18
  123. * IEEE -1, 1 10^6 1.9e-16 5.4e-17
  124. *
  125. *
  126. * ERROR MESSAGES:
  127. *
  128. * message condition value returned
  129. * asin domain |x| > 1 NAN
  130. *
  131. */
  132. /* acos()
  133. *
  134. * Inverse circular cosine
  135. *
  136. *
  137. *
  138. * SYNOPSIS:
  139. *
  140. * double x, y, acos();
  141. *
  142. * y = acos( x );
  143. *
  144. *
  145. *
  146. * DESCRIPTION:
  147. *
  148. * Returns radian angle between 0 and pi whose cosine
  149. * is x.
  150. *
  151. * Analytically, acos(x) = pi/2 - asin(x). However if |x| is
  152. * near 1, there is cancellation error in subtracting asin(x)
  153. * from pi/2. Hence if x < -0.5,
  154. *
  155. * acos(x) = pi - 2.0 * asin( sqrt((1+x)/2) );
  156. *
  157. * or if x > +0.5,
  158. *
  159. * acos(x) = 2.0 * asin( sqrt((1-x)/2) ).
  160. *
  161. *
  162. * ACCURACY:
  163. *
  164. * Relative error:
  165. * arithmetic domain # trials peak rms
  166. * DEC -1, 1 50000 3.3e-17 8.2e-18
  167. * IEEE -1, 1 10^6 2.2e-16 6.5e-17
  168. *
  169. *
  170. * ERROR MESSAGES:
  171. *
  172. * message condition value returned
  173. * asin domain |x| > 1 NAN
  174. */
  175. /* asinh.c
  176. *
  177. * Inverse hyperbolic sine
  178. *
  179. *
  180. *
  181. * SYNOPSIS:
  182. *
  183. * double x, y, asinh();
  184. *
  185. * y = asinh( x );
  186. *
  187. *
  188. *
  189. * DESCRIPTION:
  190. *
  191. * Returns inverse hyperbolic sine of argument.
  192. *
  193. * If |x| < 0.5, the function is approximated by a rational
  194. * form x + x**3 P(x)/Q(x). Otherwise,
  195. *
  196. * asinh(x) = log( x + sqrt(1 + x*x) ).
  197. *
  198. *
  199. *
  200. * ACCURACY:
  201. *
  202. * Relative error:
  203. * arithmetic domain # trials peak rms
  204. * DEC -3,3 75000 4.6e-17 1.1e-17
  205. * IEEE -1,1 30000 3.7e-16 7.8e-17
  206. * IEEE 1,3 30000 2.5e-16 6.7e-17
  207. *
  208. */
  209. /* atan.c
  210. *
  211. * Inverse circular tangent
  212. * (arctangent)
  213. *
  214. *
  215. *
  216. * SYNOPSIS:
  217. *
  218. * double x, y, atan();
  219. *
  220. * y = atan( x );
  221. *
  222. *
  223. *
  224. * DESCRIPTION:
  225. *
  226. * Returns radian angle between -pi/2 and +pi/2 whose tangent
  227. * is x.
  228. *
  229. * Range reduction is from three intervals into the interval
  230. * from zero to 0.66. The approximant uses a rational
  231. * function of degree 4/5 of the form x + x**3 P(x)/Q(x).
  232. *
  233. *
  234. *
  235. * ACCURACY:
  236. *
  237. * Relative error:
  238. * arithmetic domain # trials peak rms
  239. * DEC -10, 10 50000 2.4e-17 8.3e-18
  240. * IEEE -10, 10 10^6 1.8e-16 5.0e-17
  241. *
  242. */
  243. /* atan2()
  244. *
  245. * Quadrant correct inverse circular tangent
  246. *
  247. *
  248. *
  249. * SYNOPSIS:
  250. *
  251. * double x, y, z, atan2();
  252. *
  253. * z = atan2( y, x );
  254. *
  255. *
  256. *
  257. * DESCRIPTION:
  258. *
  259. * Returns radian angle whose tangent is y/x.
  260. * Define compile time symbol ANSIC = 1 for ANSI standard,
  261. * range -PI < z <= +PI, args (y,x); else ANSIC = 0 for range
  262. * 0 to 2PI, args (x,y).
  263. *
  264. *
  265. *
  266. * ACCURACY:
  267. *
  268. * Relative error:
  269. * arithmetic domain # trials peak rms
  270. * IEEE -10, 10 10^6 2.5e-16 6.9e-17
  271. * See atan.c.
  272. *
  273. */
  274. /* atanh.c
  275. *
  276. * Inverse hyperbolic tangent
  277. *
  278. *
  279. *
  280. * SYNOPSIS:
  281. *
  282. * double x, y, atanh();
  283. *
  284. * y = atanh( x );
  285. *
  286. *
  287. *
  288. * DESCRIPTION:
  289. *
  290. * Returns inverse hyperbolic tangent of argument in the range
  291. * MINLOG to MAXLOG.
  292. *
  293. * If |x| < 0.5, the rational form x + x**3 P(x)/Q(x) is
  294. * employed. Otherwise,
  295. * atanh(x) = 0.5 * log( (1+x)/(1-x) ).
  296. *
  297. *
  298. *
  299. * ACCURACY:
  300. *
  301. * Relative error:
  302. * arithmetic domain # trials peak rms
  303. * DEC -1,1 50000 2.4e-17 6.4e-18
  304. * IEEE -1,1 30000 1.9e-16 5.2e-17
  305. *
  306. */
  307. /* bdtr.c
  308. *
  309. * Binomial distribution
  310. *
  311. *
  312. *
  313. * SYNOPSIS:
  314. *
  315. * int k, n;
  316. * double p, y, bdtr();
  317. *
  318. * y = bdtr( k, n, p );
  319. *
  320. * DESCRIPTION:
  321. *
  322. * Returns the sum of the terms 0 through k of the Binomial
  323. * probability density:
  324. *
  325. * k
  326. * -- ( n ) j n-j
  327. * > ( ) p (1-p)
  328. * -- ( j )
  329. * j=0
  330. *
  331. * The terms are not summed directly; instead the incomplete
  332. * beta integral is employed, according to the formula
  333. *
  334. * y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
  335. *
  336. * The arguments must be positive, with p ranging from 0 to 1.
  337. *
  338. * ACCURACY:
  339. *
  340. * Tested at random points (a,b,p), with p between 0 and 1.
  341. *
  342. * a,b Relative error:
  343. * arithmetic domain # trials peak rms
  344. * For p between 0.001 and 1:
  345. * IEEE 0,100 100000 4.3e-15 2.6e-16
  346. * See also incbet.c.
  347. *
  348. * ERROR MESSAGES:
  349. *
  350. * message condition value returned
  351. * bdtr domain k < 0 0.0
  352. * n < k
  353. * x < 0, x > 1
  354. */
  355. /* bdtrc()
  356. *
  357. * Complemented binomial distribution
  358. *
  359. *
  360. *
  361. * SYNOPSIS:
  362. *
  363. * int k, n;
  364. * double p, y, bdtrc();
  365. *
  366. * y = bdtrc( k, n, p );
  367. *
  368. * DESCRIPTION:
  369. *
  370. * Returns the sum of the terms k+1 through n of the Binomial
  371. * probability density:
  372. *
  373. * n
  374. * -- ( n ) j n-j
  375. * > ( ) p (1-p)
  376. * -- ( j )
  377. * j=k+1
  378. *
  379. * The terms are not summed directly; instead the incomplete
  380. * beta integral is employed, according to the formula
  381. *
  382. * y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
  383. *
  384. * The arguments must be positive, with p ranging from 0 to 1.
  385. *
  386. * ACCURACY:
  387. *
  388. * Tested at random points (a,b,p).
  389. *
  390. * a,b Relative error:
  391. * arithmetic domain # trials peak rms
  392. * For p between 0.001 and 1:
  393. * IEEE 0,100 100000 6.7e-15 8.2e-16
  394. * For p between 0 and .001:
  395. * IEEE 0,100 100000 1.5e-13 2.7e-15
  396. *
  397. * ERROR MESSAGES:
  398. *
  399. * message condition value returned
  400. * bdtrc domain x<0, x>1, n<k 0.0
  401. */
  402. /* bdtri()
  403. *
  404. * Inverse binomial distribution
  405. *
  406. *
  407. *
  408. * SYNOPSIS:
  409. *
  410. * int k, n;
  411. * double p, y, bdtri();
  412. *
  413. * p = bdtr( k, n, y );
  414. *
  415. * DESCRIPTION:
  416. *
  417. * Finds the event probability p such that the sum of the
  418. * terms 0 through k of the Binomial probability density
  419. * is equal to the given cumulative probability y.
  420. *
  421. * This is accomplished using the inverse beta integral
  422. * function and the relation
  423. *
  424. * 1 - p = incbi( n-k, k+1, y ).
  425. *
  426. * ACCURACY:
  427. *
  428. * Tested at random points (a,b,p).
  429. *
  430. * a,b Relative error:
  431. * arithmetic domain # trials peak rms
  432. * For p between 0.001 and 1:
  433. * IEEE 0,100 100000 2.3e-14 6.4e-16
  434. * IEEE 0,10000 100000 6.6e-12 1.2e-13
  435. * For p between 10^-6 and 0.001:
  436. * IEEE 0,100 100000 2.0e-12 1.3e-14
  437. * IEEE 0,10000 100000 1.5e-12 3.2e-14
  438. * See also incbi.c.
  439. *
  440. * ERROR MESSAGES:
  441. *
  442. * message condition value returned
  443. * bdtri domain k < 0, n <= k 0.0
  444. * x < 0, x > 1
  445. */
  446. /* beta.c
  447. *
  448. * Beta function
  449. *
  450. *
  451. *
  452. * SYNOPSIS:
  453. *
  454. * double a, b, y, beta();
  455. *
  456. * y = beta( a, b );
  457. *
  458. *
  459. *
  460. * DESCRIPTION:
  461. *
  462. * - -
  463. * | (a) | (b)
  464. * beta( a, b ) = -----------.
  465. * -
  466. * | (a+b)
  467. *
  468. * For large arguments the logarithm of the function is
  469. * evaluated using lgam(), then exponentiated.
  470. *
  471. *
  472. *
  473. * ACCURACY:
  474. *
  475. * Relative error:
  476. * arithmetic domain # trials peak rms
  477. * DEC 0,30 1700 7.7e-15 1.5e-15
  478. * IEEE 0,30 30000 8.1e-14 1.1e-14
  479. *
  480. * ERROR MESSAGES:
  481. *
  482. * message condition value returned
  483. * beta overflow log(beta) > MAXLOG 0.0
  484. * a or b <0 integer 0.0
  485. *
  486. */
  487. /* btdtr.c
  488. *
  489. * Beta distribution
  490. *
  491. *
  492. *
  493. * SYNOPSIS:
  494. *
  495. * double a, b, x, y, btdtr();
  496. *
  497. * y = btdtr( a, b, x );
  498. *
  499. *
  500. *
  501. * DESCRIPTION:
  502. *
  503. * Returns the area from zero to x under the beta density
  504. * function:
  505. *
  506. *
  507. * x
  508. * - -
  509. * | (a+b) | | a-1 b-1
  510. * P(x) = ---------- | t (1-t) dt
  511. * - - | |
  512. * | (a) | (b) -
  513. * 0
  514. *
  515. *
  516. * This function is identical to the incomplete beta
  517. * integral function incbet(a, b, x).
  518. *
  519. * The complemented function is
  520. *
  521. * 1 - P(1-x) = incbet( b, a, x );
  522. *
  523. *
  524. * ACCURACY:
  525. *
  526. * See incbet.c.
  527. *
  528. */
  529. /* cbrt.c
  530. *
  531. * Cube root
  532. *
  533. *
  534. *
  535. * SYNOPSIS:
  536. *
  537. * double x, y, cbrt();
  538. *
  539. * y = cbrt( x );
  540. *
  541. *
  542. *
  543. * DESCRIPTION:
  544. *
  545. * Returns the cube root of the argument, which may be negative.
  546. *
  547. * Range reduction involves determining the power of 2 of
  548. * the argument. A polynomial of degree 2 applied to the
  549. * mantissa, and multiplication by the cube root of 1, 2, or 4
  550. * approximates the root to within about 0.1%. Then Newton's
  551. * iteration is used three times to converge to an accurate
  552. * result.
  553. *
  554. *
  555. *
  556. * ACCURACY:
  557. *
  558. * Relative error:
  559. * arithmetic domain # trials peak rms
  560. * DEC -10,10 200000 1.8e-17 6.2e-18
  561. * IEEE 0,1e308 30000 1.5e-16 5.0e-17
  562. *
  563. */
  564. /* chbevl.c
  565. *
  566. * Evaluate Chebyshev series
  567. *
  568. *
  569. *
  570. * SYNOPSIS:
  571. *
  572. * int N;
  573. * double x, y, coef[N], chebevl();
  574. *
  575. * y = chbevl( x, coef, N );
  576. *
  577. *
  578. *
  579. * DESCRIPTION:
  580. *
  581. * Evaluates the series
  582. *
  583. * N-1
  584. * - '
  585. * y = > coef[i] T (x/2)
  586. * - i
  587. * i=0
  588. *
  589. * of Chebyshev polynomials Ti at argument x/2.
  590. *
  591. * Coefficients are stored in reverse order, i.e. the zero
  592. * order term is last in the array. Note N is the number of
  593. * coefficients, not the order.
  594. *
  595. * If coefficients are for the interval a to b, x must
  596. * have been transformed to x -> 2(2x - b - a)/(b-a) before
  597. * entering the routine. This maps x from (a, b) to (-1, 1),
  598. * over which the Chebyshev polynomials are defined.
  599. *
  600. * If the coefficients are for the inverted interval, in
  601. * which (a, b) is mapped to (1/b, 1/a), the transformation
  602. * required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity,
  603. * this becomes x -> 4a/x - 1.
  604. *
  605. *
  606. *
  607. * SPEED:
  608. *
  609. * Taking advantage of the recurrence properties of the
  610. * Chebyshev polynomials, the routine requires one more
  611. * addition per loop than evaluating a nested polynomial of
  612. * the same degree.
  613. *
  614. */
  615. /* chdtr.c
  616. *
  617. * Chi-square distribution
  618. *
  619. *
  620. *
  621. * SYNOPSIS:
  622. *
  623. * double df, x, y, chdtr();
  624. *
  625. * y = chdtr( df, x );
  626. *
  627. *
  628. *
  629. * DESCRIPTION:
  630. *
  631. * Returns the area under the left hand tail (from 0 to x)
  632. * of the Chi square probability density function with
  633. * v degrees of freedom.
  634. *
  635. *
  636. * inf.
  637. * -
  638. * 1 | | v/2-1 -t/2
  639. * P( x | v ) = ----------- | t e dt
  640. * v/2 - | |
  641. * 2 | (v/2) -
  642. * x
  643. *
  644. * where x is the Chi-square variable.
  645. *
  646. * The incomplete gamma integral is used, according to the
  647. * formula
  648. *
  649. * y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
  650. *
  651. *
  652. * The arguments must both be positive.
  653. *
  654. *
  655. *
  656. * ACCURACY:
  657. *
  658. * See igam().
  659. *
  660. * ERROR MESSAGES:
  661. *
  662. * message condition value returned
  663. * chdtr domain x < 0 or v < 1 0.0
  664. */
  665. /* chdtrc()
  666. *
  667. * Complemented Chi-square distribution
  668. *
  669. *
  670. *
  671. * SYNOPSIS:
  672. *
  673. * double v, x, y, chdtrc();
  674. *
  675. * y = chdtrc( v, x );
  676. *
  677. *
  678. *
  679. * DESCRIPTION:
  680. *
  681. * Returns the area under the right hand tail (from x to
  682. * infinity) of the Chi square probability density function
  683. * with v degrees of freedom:
  684. *
  685. *
  686. * inf.
  687. * -
  688. * 1 | | v/2-1 -t/2
  689. * P( x | v ) = ----------- | t e dt
  690. * v/2 - | |
  691. * 2 | (v/2) -
  692. * x
  693. *
  694. * where x is the Chi-square variable.
  695. *
  696. * The incomplete gamma integral is used, according to the
  697. * formula
  698. *
  699. * y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
  700. *
  701. *
  702. * The arguments must both be positive.
  703. *
  704. *
  705. *
  706. * ACCURACY:
  707. *
  708. * See igamc().
  709. *
  710. * ERROR MESSAGES:
  711. *
  712. * message condition value returned
  713. * chdtrc domain x < 0 or v < 1 0.0
  714. */
  715. /* chdtri()
  716. *
  717. * Inverse of complemented Chi-square distribution
  718. *
  719. *
  720. *
  721. * SYNOPSIS:
  722. *
  723. * double df, x, y, chdtri();
  724. *
  725. * x = chdtri( df, y );
  726. *
  727. *
  728. *
  729. *
  730. * DESCRIPTION:
  731. *
  732. * Finds the Chi-square argument x such that the integral
  733. * from x to infinity of the Chi-square density is equal
  734. * to the given cumulative probability y.
  735. *
  736. * This is accomplished using the inverse gamma integral
  737. * function and the relation
  738. *
  739. * x/2 = igami( df/2, y );
  740. *
  741. *
  742. *
  743. *
  744. * ACCURACY:
  745. *
  746. * See igami.c.
  747. *
  748. * ERROR MESSAGES:
  749. *
  750. * message condition value returned
  751. * chdtri domain y < 0 or y > 1 0.0
  752. * v < 1
  753. *
  754. */
  755. /* clog.c
  756. *
  757. * Complex natural logarithm
  758. *
  759. *
  760. *
  761. * SYNOPSIS:
  762. *
  763. * void clog();
  764. * cmplx z, w;
  765. *
  766. * clog( &z, &w );
  767. *
  768. *
  769. *
  770. * DESCRIPTION:
  771. *
  772. * Returns complex logarithm to the base e (2.718...) of
  773. * the complex argument x.
  774. *
  775. * If z = x + iy, r = sqrt( x**2 + y**2 ),
  776. * then
  777. * w = log(r) + i arctan(y/x).
  778. *
  779. * The arctangent ranges from -PI to +PI.
  780. *
  781. *
  782. * ACCURACY:
  783. *
  784. * Relative error:
  785. * arithmetic domain # trials peak rms
  786. * DEC -10,+10 7000 8.5e-17 1.9e-17
  787. * IEEE -10,+10 30000 5.0e-15 1.1e-16
  788. *
  789. * Larger relative error can be observed for z near 1 +i0.
  790. * In IEEE arithmetic the peak absolute error is 5.2e-16, rms
  791. * absolute error 1.0e-16.
  792. */
  793. /* cexp()
  794. *
  795. * Complex exponential function
  796. *
  797. *
  798. *
  799. * SYNOPSIS:
  800. *
  801. * void cexp();
  802. * cmplx z, w;
  803. *
  804. * cexp( &z, &w );
  805. *
  806. *
  807. *
  808. * DESCRIPTION:
  809. *
  810. * Returns the exponential of the complex argument z
  811. * into the complex result w.
  812. *
  813. * If
  814. * z = x + iy,
  815. * r = exp(x),
  816. *
  817. * then
  818. *
  819. * w = r cos y + i r sin y.
  820. *
  821. *
  822. * ACCURACY:
  823. *
  824. * Relative error:
  825. * arithmetic domain # trials peak rms
  826. * DEC -10,+10 8700 3.7e-17 1.1e-17
  827. * IEEE -10,+10 30000 3.0e-16 8.7e-17
  828. *
  829. */
  830. /* csin()
  831. *
  832. * Complex circular sine
  833. *
  834. *
  835. *
  836. * SYNOPSIS:
  837. *
  838. * void csin();
  839. * cmplx z, w;
  840. *
  841. * csin( &z, &w );
  842. *
  843. *
  844. *
  845. * DESCRIPTION:
  846. *
  847. * If
  848. * z = x + iy,
  849. *
  850. * then
  851. *
  852. * w = sin x cosh y + i cos x sinh y.
  853. *
  854. *
  855. *
  856. * ACCURACY:
  857. *
  858. * Relative error:
  859. * arithmetic domain # trials peak rms
  860. * DEC -10,+10 8400 5.3e-17 1.3e-17
  861. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  862. * Also tested by csin(casin(z)) = z.
  863. *
  864. */
  865. /* ccos()
  866. *
  867. * Complex circular cosine
  868. *
  869. *
  870. *
  871. * SYNOPSIS:
  872. *
  873. * void ccos();
  874. * cmplx z, w;
  875. *
  876. * ccos( &z, &w );
  877. *
  878. *
  879. *
  880. * DESCRIPTION:
  881. *
  882. * If
  883. * z = x + iy,
  884. *
  885. * then
  886. *
  887. * w = cos x cosh y - i sin x sinh y.
  888. *
  889. *
  890. *
  891. * ACCURACY:
  892. *
  893. * Relative error:
  894. * arithmetic domain # trials peak rms
  895. * DEC -10,+10 8400 4.5e-17 1.3e-17
  896. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  897. */
  898. /* ctan()
  899. *
  900. * Complex circular tangent
  901. *
  902. *
  903. *
  904. * SYNOPSIS:
  905. *
  906. * void ctan();
  907. * cmplx z, w;
  908. *
  909. * ctan( &z, &w );
  910. *
  911. *
  912. *
  913. * DESCRIPTION:
  914. *
  915. * If
  916. * z = x + iy,
  917. *
  918. * then
  919. *
  920. * sin 2x + i sinh 2y
  921. * w = --------------------.
  922. * cos 2x + cosh 2y
  923. *
  924. * On the real axis the denominator is zero at odd multiples
  925. * of PI/2. The denominator is evaluated by its Taylor
  926. * series near these points.
  927. *
  928. *
  929. * ACCURACY:
  930. *
  931. * Relative error:
  932. * arithmetic domain # trials peak rms
  933. * DEC -10,+10 5200 7.1e-17 1.6e-17
  934. * IEEE -10,+10 30000 7.2e-16 1.2e-16
  935. * Also tested by ctan * ccot = 1 and catan(ctan(z)) = z.
  936. */
  937. /* ccot()
  938. *
  939. * Complex circular cotangent
  940. *
  941. *
  942. *
  943. * SYNOPSIS:
  944. *
  945. * void ccot();
  946. * cmplx z, w;
  947. *
  948. * ccot( &z, &w );
  949. *
  950. *
  951. *
  952. * DESCRIPTION:
  953. *
  954. * If
  955. * z = x + iy,
  956. *
  957. * then
  958. *
  959. * sin 2x - i sinh 2y
  960. * w = --------------------.
  961. * cosh 2y - cos 2x
  962. *
  963. * On the real axis, the denominator has zeros at even
  964. * multiples of PI/2. Near these points it is evaluated
  965. * by a Taylor series.
  966. *
  967. *
  968. * ACCURACY:
  969. *
  970. * Relative error:
  971. * arithmetic domain # trials peak rms
  972. * DEC -10,+10 3000 6.5e-17 1.6e-17
  973. * IEEE -10,+10 30000 9.2e-16 1.2e-16
  974. * Also tested by ctan * ccot = 1 + i0.
  975. */
  976. /* casin()
  977. *
  978. * Complex circular arc sine
  979. *
  980. *
  981. *
  982. * SYNOPSIS:
  983. *
  984. * void casin();
  985. * cmplx z, w;
  986. *
  987. * casin( &z, &w );
  988. *
  989. *
  990. *
  991. * DESCRIPTION:
  992. *
  993. * Inverse complex sine:
  994. *
  995. * 2
  996. * w = -i clog( iz + csqrt( 1 - z ) ).
  997. *
  998. *
  999. * ACCURACY:
  1000. *
  1001. * Relative error:
  1002. * arithmetic domain # trials peak rms
  1003. * DEC -10,+10 10100 2.1e-15 3.4e-16
  1004. * IEEE -10,+10 30000 2.2e-14 2.7e-15
  1005. * Larger relative error can be observed for z near zero.
  1006. * Also tested by csin(casin(z)) = z.
  1007. */
  1008. /* cacos()
  1009. *
  1010. * Complex circular arc cosine
  1011. *
  1012. *
  1013. *
  1014. * SYNOPSIS:
  1015. *
  1016. * void cacos();
  1017. * cmplx z, w;
  1018. *
  1019. * cacos( &z, &w );
  1020. *
  1021. *
  1022. *
  1023. * DESCRIPTION:
  1024. *
  1025. *
  1026. * w = arccos z = PI/2 - arcsin z.
  1027. *
  1028. *
  1029. *
  1030. *
  1031. * ACCURACY:
  1032. *
  1033. * Relative error:
  1034. * arithmetic domain # trials peak rms
  1035. * DEC -10,+10 5200 1.6e-15 2.8e-16
  1036. * IEEE -10,+10 30000 1.8e-14 2.2e-15
  1037. */
  1038. /* catan()
  1039. *
  1040. * Complex circular arc tangent
  1041. *
  1042. *
  1043. *
  1044. * SYNOPSIS:
  1045. *
  1046. * void catan();
  1047. * cmplx z, w;
  1048. *
  1049. * catan( &z, &w );
  1050. *
  1051. *
  1052. *
  1053. * DESCRIPTION:
  1054. *
  1055. * If
  1056. * z = x + iy,
  1057. *
  1058. * then
  1059. * 1 ( 2x )
  1060. * Re w = - arctan(-----------) + k PI
  1061. * 2 ( 2 2)
  1062. * (1 - x - y )
  1063. *
  1064. * ( 2 2)
  1065. * 1 (x + (y+1) )
  1066. * Im w = - log(------------)
  1067. * 4 ( 2 2)
  1068. * (x + (y-1) )
  1069. *
  1070. * Where k is an arbitrary integer.
  1071. *
  1072. *
  1073. *
  1074. * ACCURACY:
  1075. *
  1076. * Relative error:
  1077. * arithmetic domain # trials peak rms
  1078. * DEC -10,+10 5900 1.3e-16 7.8e-18
  1079. * IEEE -10,+10 30000 2.3e-15 8.5e-17
  1080. * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2,
  1081. * had peak relative error 1.5e-16, rms relative error
  1082. * 2.9e-17. See also clog().
  1083. */
  1084. /* cmplx.c
  1085. *
  1086. * Complex number arithmetic
  1087. *
  1088. *
  1089. *
  1090. * SYNOPSIS:
  1091. *
  1092. * typedef struct {
  1093. * double r; real part
  1094. * double i; imaginary part
  1095. * }cmplx;
  1096. *
  1097. * cmplx *a, *b, *c;
  1098. *
  1099. * cadd( a, b, c ); c = b + a
  1100. * csub( a, b, c ); c = b - a
  1101. * cmul( a, b, c ); c = b * a
  1102. * cdiv( a, b, c ); c = b / a
  1103. * cneg( c ); c = -c
  1104. * cmov( b, c ); c = b
  1105. *
  1106. *
  1107. *
  1108. * DESCRIPTION:
  1109. *
  1110. * Addition:
  1111. * c.r = b.r + a.r
  1112. * c.i = b.i + a.i
  1113. *
  1114. * Subtraction:
  1115. * c.r = b.r - a.r
  1116. * c.i = b.i - a.i
  1117. *
  1118. * Multiplication:
  1119. * c.r = b.r * a.r - b.i * a.i
  1120. * c.i = b.r * a.i + b.i * a.r
  1121. *
  1122. * Division:
  1123. * d = a.r * a.r + a.i * a.i
  1124. * c.r = (b.r * a.r + b.i * a.i)/d
  1125. * c.i = (b.i * a.r - b.r * a.i)/d
  1126. * ACCURACY:
  1127. *
  1128. * In DEC arithmetic, the test (1/z) * z = 1 had peak relative
  1129. * error 3.1e-17, rms 1.2e-17. The test (y/z) * (z/y) = 1 had
  1130. * peak relative error 8.3e-17, rms 2.1e-17.
  1131. *
  1132. * Tests in the rectangle {-10,+10}:
  1133. * Relative error:
  1134. * arithmetic function # trials peak rms
  1135. * DEC cadd 10000 1.4e-17 3.4e-18
  1136. * IEEE cadd 100000 1.1e-16 2.7e-17
  1137. * DEC csub 10000 1.4e-17 4.5e-18
  1138. * IEEE csub 100000 1.1e-16 3.4e-17
  1139. * DEC cmul 3000 2.3e-17 8.7e-18
  1140. * IEEE cmul 100000 2.1e-16 6.9e-17
  1141. * DEC cdiv 18000 4.9e-17 1.3e-17
  1142. * IEEE cdiv 100000 3.7e-16 1.1e-16
  1143. */
  1144. /* cabs()
  1145. *
  1146. * Complex absolute value
  1147. *
  1148. *
  1149. *
  1150. * SYNOPSIS:
  1151. *
  1152. * double cabs();
  1153. * cmplx z;
  1154. * double a;
  1155. *
  1156. * a = cabs( &z );
  1157. *
  1158. *
  1159. *
  1160. * DESCRIPTION:
  1161. *
  1162. *
  1163. * If z = x + iy
  1164. *
  1165. * then
  1166. *
  1167. * a = sqrt( x**2 + y**2 ).
  1168. *
  1169. * Overflow and underflow are avoided by testing the magnitudes
  1170. * of x and y before squaring. If either is outside half of
  1171. * the floating point full scale range, both are rescaled.
  1172. *
  1173. *
  1174. * ACCURACY:
  1175. *
  1176. * Relative error:
  1177. * arithmetic domain # trials peak rms
  1178. * DEC -30,+30 30000 3.2e-17 9.2e-18
  1179. * IEEE -10,+10 100000 2.7e-16 6.9e-17
  1180. */
  1181. /* csqrt()
  1182. *
  1183. * Complex square root
  1184. *
  1185. *
  1186. *
  1187. * SYNOPSIS:
  1188. *
  1189. * void csqrt();
  1190. * cmplx z, w;
  1191. *
  1192. * csqrt( &z, &w );
  1193. *
  1194. *
  1195. *
  1196. * DESCRIPTION:
  1197. *
  1198. *
  1199. * If z = x + iy, r = |z|, then
  1200. *
  1201. * 1/2
  1202. * Im w = [ (r - x)/2 ] ,
  1203. *
  1204. * Re w = y / 2 Im w.
  1205. *
  1206. *
  1207. * Note that -w is also a square root of z. The root chosen
  1208. * is always in the upper half plane.
  1209. *
  1210. * Because of the potential for cancellation error in r - x,
  1211. * the result is sharpened by doing a Heron iteration
  1212. * (see sqrt.c) in complex arithmetic.
  1213. *
  1214. *
  1215. *
  1216. * ACCURACY:
  1217. *
  1218. * Relative error:
  1219. * arithmetic domain # trials peak rms
  1220. * DEC -10,+10 25000 3.2e-17 9.6e-18
  1221. * IEEE -10,+10 100000 3.2e-16 7.7e-17
  1222. *
  1223. * 2
  1224. * Also tested by csqrt( z ) = z, and tested by arguments
  1225. * close to the real axis.
  1226. */
  1227. /* const.c
  1228. *
  1229. * Globally declared constants
  1230. *
  1231. *
  1232. *
  1233. * SYNOPSIS:
  1234. *
  1235. * extern double nameofconstant;
  1236. *
  1237. *
  1238. *
  1239. *
  1240. * DESCRIPTION:
  1241. *
  1242. * This file contains a number of mathematical constants and
  1243. * also some needed size parameters of the computer arithmetic.
  1244. * The values are supplied as arrays of hexadecimal integers
  1245. * for IEEE arithmetic; arrays of octal constants for DEC
  1246. * arithmetic; and in a normal decimal scientific notation for
  1247. * other machines. The particular notation used is determined
  1248. * by a symbol (DEC, IBMPC, or UNK) defined in the include file
  1249. * math.h.
  1250. *
  1251. * The default size parameters are as follows.
  1252. *
  1253. * For DEC and UNK modes:
  1254. * MACHEP = 1.38777878078144567553E-17 2**-56
  1255. * MAXLOG = 8.8029691931113054295988E1 log(2**127)
  1256. * MINLOG = -8.872283911167299960540E1 log(2**-128)
  1257. * MAXNUM = 1.701411834604692317316873e38 2**127
  1258. *
  1259. * For IEEE arithmetic (IBMPC):
  1260. * MACHEP = 1.11022302462515654042E-16 2**-53
  1261. * MAXLOG = 7.09782712893383996843E2 log(2**1024)
  1262. * MINLOG = -7.08396418532264106224E2 log(2**-1022)
  1263. * MAXNUM = 1.7976931348623158E308 2**1024
  1264. *
  1265. * The global symbols for mathematical constants are
  1266. * PI = 3.14159265358979323846 pi
  1267. * PIO2 = 1.57079632679489661923 pi/2
  1268. * PIO4 = 7.85398163397448309616E-1 pi/4
  1269. * SQRT2 = 1.41421356237309504880 sqrt(2)
  1270. * SQRTH = 7.07106781186547524401E-1 sqrt(2)/2
  1271. * LOG2E = 1.4426950408889634073599 1/log(2)
  1272. * SQ2OPI = 7.9788456080286535587989E-1 sqrt( 2/pi )
  1273. * LOGE2 = 6.93147180559945309417E-1 log(2)
  1274. * LOGSQ2 = 3.46573590279972654709E-1 log(2)/2
  1275. * THPIO4 = 2.35619449019234492885 3*pi/4
  1276. * TWOOPI = 6.36619772367581343075535E-1 2/pi
  1277. *
  1278. * These lists are subject to change.
  1279. */
  1280. /* cosh.c
  1281. *
  1282. * Hyperbolic cosine
  1283. *
  1284. *
  1285. *
  1286. * SYNOPSIS:
  1287. *
  1288. * double x, y, cosh();
  1289. *
  1290. * y = cosh( x );
  1291. *
  1292. *
  1293. *
  1294. * DESCRIPTION:
  1295. *
  1296. * Returns hyperbolic cosine of argument in the range MINLOG to
  1297. * MAXLOG.
  1298. *
  1299. * cosh(x) = ( exp(x) + exp(-x) )/2.
  1300. *
  1301. *
  1302. *
  1303. * ACCURACY:
  1304. *
  1305. * Relative error:
  1306. * arithmetic domain # trials peak rms
  1307. * DEC +- 88 50000 4.0e-17 7.7e-18
  1308. * IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
  1309. *
  1310. *
  1311. * ERROR MESSAGES:
  1312. *
  1313. * message condition value returned
  1314. * cosh overflow |x| > MAXLOG MAXNUM
  1315. *
  1316. *
  1317. */
  1318. /* cpmul.c
  1319. *
  1320. * Multiply two polynomials with complex coefficients
  1321. *
  1322. *
  1323. *
  1324. * SYNOPSIS:
  1325. *
  1326. * typedef struct
  1327. * {
  1328. * double r;
  1329. * double i;
  1330. * }cmplx;
  1331. *
  1332. * cmplx a[], b[], c[];
  1333. * int da, db, dc;
  1334. *
  1335. * cpmul( a, da, b, db, c, &dc );
  1336. *
  1337. *
  1338. *
  1339. * DESCRIPTION:
  1340. *
  1341. * The two argument polynomials are multiplied together, and
  1342. * their product is placed in c.
  1343. *
  1344. * Each polynomial is represented by its coefficients stored
  1345. * as an array of complex number structures (see the typedef).
  1346. * The degree of a is da, which must be passed to the routine
  1347. * as an argument; similarly the degree db of b is an argument.
  1348. * Array a has da + 1 elements and array b has db + 1 elements.
  1349. * Array c must have storage allocated for at least da + db + 1
  1350. * elements. The value da + db is returned in dc; this is
  1351. * the degree of the product polynomial.
  1352. *
  1353. * Polynomial coefficients are stored in ascending order; i.e.,
  1354. * a(x) = a[0]*x**0 + a[1]*x**1 + ... + a[da]*x**da.
  1355. *
  1356. *
  1357. * If desired, c may be the same as either a or b, in which
  1358. * case the input argument array is replaced by the product
  1359. * array (but only up to terms of degree da + db).
  1360. *
  1361. */
  1362. /* dawsn.c
  1363. *
  1364. * Dawson's Integral
  1365. *
  1366. *
  1367. *
  1368. * SYNOPSIS:
  1369. *
  1370. * double x, y, dawsn();
  1371. *
  1372. * y = dawsn( x );
  1373. *
  1374. *
  1375. *
  1376. * DESCRIPTION:
  1377. *
  1378. * Approximates the integral
  1379. *
  1380. * x
  1381. * -
  1382. * 2 | | 2
  1383. * dawsn(x) = exp( -x ) | exp( t ) dt
  1384. * | |
  1385. * -
  1386. * 0
  1387. *
  1388. * Three different rational approximations are employed, for
  1389. * the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
  1390. *
  1391. *
  1392. * ACCURACY:
  1393. *
  1394. * Relative error:
  1395. * arithmetic domain # trials peak rms
  1396. * IEEE 0,10 10000 6.9e-16 1.0e-16
  1397. * DEC 0,10 6000 7.4e-17 1.4e-17
  1398. *
  1399. *
  1400. */
  1401. /* drand.c
  1402. *
  1403. * Pseudorandom number generator
  1404. *
  1405. *
  1406. *
  1407. * SYNOPSIS:
  1408. *
  1409. * double y, drand();
  1410. *
  1411. * drand( &y );
  1412. *
  1413. *
  1414. *
  1415. * DESCRIPTION:
  1416. *
  1417. * Yields a random number 1.0 <= y < 2.0.
  1418. *
  1419. * The three-generator congruential algorithm by Brian
  1420. * Wichmann and David Hill (BYTE magazine, March, 1987,
  1421. * pp 127-8) is used. The period, given by them, is
  1422. * 6953607871644.
  1423. *
  1424. * Versions invoked by the different arithmetic compile
  1425. * time options DEC, IBMPC, and MIEEE, produce
  1426. * approximately the same sequences, differing only in the
  1427. * least significant bits of the numbers. The UNK option
  1428. * implements the algorithm as recommended in the BYTE
  1429. * article. It may be used on all computers. However,
  1430. * the low order bits of a double precision number may
  1431. * not be adequately random, and may vary due to arithmetic
  1432. * implementation details on different computers.
  1433. *
  1434. * The other compile options generate an additional random
  1435. * integer that overwrites the low order bits of the double
  1436. * precision number. This reduces the period by a factor of
  1437. * two but tends to overcome the problems mentioned.
  1438. *
  1439. */
  1440. /* eigens.c
  1441. *
  1442. * Eigenvalues and eigenvectors of a real symmetric matrix
  1443. *
  1444. *
  1445. *
  1446. * SYNOPSIS:
  1447. *
  1448. * int n;
  1449. * double A[n*(n+1)/2], EV[n*n], E[n];
  1450. * void eigens( A, EV, E, n );
  1451. *
  1452. *
  1453. *
  1454. * DESCRIPTION:
  1455. *
  1456. * The algorithm is due to J. vonNeumann.
  1457. *
  1458. * A[] is a symmetric matrix stored in lower triangular form.
  1459. * That is, A[ row, column ] = A[ (row*row+row)/2 + column ]
  1460. * or equivalently with row and column interchanged. The
  1461. * indices row and column run from 0 through n-1.
  1462. *
  1463. * EV[] is the output matrix of eigenvectors stored columnwise.
  1464. * That is, the elements of each eigenvector appear in sequential
  1465. * memory order. The jth element of the ith eigenvector is
  1466. * EV[ n*i+j ] = EV[i][j].
  1467. *
  1468. * E[] is the output matrix of eigenvalues. The ith element
  1469. * of E corresponds to the ith eigenvector (the ith row of EV).
  1470. *
  1471. * On output, the matrix A will have been diagonalized and its
  1472. * orginal contents are destroyed.
  1473. *
  1474. * ACCURACY:
  1475. *
  1476. * The error is controlled by an internal parameter called RANGE
  1477. * which is set to 1e-10. After diagonalization, the
  1478. * off-diagonal elements of A will have been reduced by
  1479. * this factor.
  1480. *
  1481. * ERROR MESSAGES:
  1482. *
  1483. * None.
  1484. *
  1485. */
  1486. /* ellie.c
  1487. *
  1488. * Incomplete elliptic integral of the second kind
  1489. *
  1490. *
  1491. *
  1492. * SYNOPSIS:
  1493. *
  1494. * double phi, m, y, ellie();
  1495. *
  1496. * y = ellie( phi, m );
  1497. *
  1498. *
  1499. *
  1500. * DESCRIPTION:
  1501. *
  1502. * Approximates the integral
  1503. *
  1504. *
  1505. * phi
  1506. * -
  1507. * | |
  1508. * | 2
  1509. * E(phi_\m) = | sqrt( 1 - m sin t ) dt
  1510. * |
  1511. * | |
  1512. * -
  1513. * 0
  1514. *
  1515. * of amplitude phi and modulus m, using the arithmetic -
  1516. * geometric mean algorithm.
  1517. *
  1518. *
  1519. *
  1520. * ACCURACY:
  1521. *
  1522. * Tested at random arguments with phi in [-10, 10] and m in
  1523. * [0, 1].
  1524. * Relative error:
  1525. * arithmetic domain # trials peak rms
  1526. * DEC 0,2 2000 1.9e-16 3.4e-17
  1527. * IEEE -10,10 150000 3.3e-15 1.4e-16
  1528. *
  1529. *
  1530. */
  1531. /* ellik.c
  1532. *
  1533. * Incomplete elliptic integral of the first kind
  1534. *
  1535. *
  1536. *
  1537. * SYNOPSIS:
  1538. *
  1539. * double phi, m, y, ellik();
  1540. *
  1541. * y = ellik( phi, m );
  1542. *
  1543. *
  1544. *
  1545. * DESCRIPTION:
  1546. *
  1547. * Approximates the integral
  1548. *
  1549. *
  1550. *
  1551. * phi
  1552. * -
  1553. * | |
  1554. * | dt
  1555. * F(phi_\m) = | ------------------
  1556. * | 2
  1557. * | | sqrt( 1 - m sin t )
  1558. * -
  1559. * 0
  1560. *
  1561. * of amplitude phi and modulus m, using the arithmetic -
  1562. * geometric mean algorithm.
  1563. *
  1564. *
  1565. *
  1566. *
  1567. * ACCURACY:
  1568. *
  1569. * Tested at random points with m in [0, 1] and phi as indicated.
  1570. *
  1571. * Relative error:
  1572. * arithmetic domain # trials peak rms
  1573. * IEEE -10,10 200000 7.4e-16 1.0e-16
  1574. *
  1575. *
  1576. */
  1577. /* ellpe.c
  1578. *
  1579. * Complete elliptic integral of the second kind
  1580. *
  1581. *
  1582. *
  1583. * SYNOPSIS:
  1584. *
  1585. * double m1, y, ellpe();
  1586. *
  1587. * y = ellpe( m1 );
  1588. *
  1589. *
  1590. *
  1591. * DESCRIPTION:
  1592. *
  1593. * Approximates the integral
  1594. *
  1595. *
  1596. * pi/2
  1597. * -
  1598. * | | 2
  1599. * E(m) = | sqrt( 1 - m sin t ) dt
  1600. * | |
  1601. * -
  1602. * 0
  1603. *
  1604. * Where m = 1 - m1, using the approximation
  1605. *
  1606. * P(x) - x log x Q(x).
  1607. *
  1608. * Though there are no singularities, the argument m1 is used
  1609. * rather than m for compatibility with ellpk().
  1610. *
  1611. * E(1) = 1; E(0) = pi/2.
  1612. *
  1613. *
  1614. * ACCURACY:
  1615. *
  1616. * Relative error:
  1617. * arithmetic domain # trials peak rms
  1618. * DEC 0, 1 13000 3.1e-17 9.4e-18
  1619. * IEEE 0, 1 10000 2.1e-16 7.3e-17
  1620. *
  1621. *
  1622. * ERROR MESSAGES:
  1623. *
  1624. * message condition value returned
  1625. * ellpe domain x<0, x>1 0.0
  1626. *
  1627. */
  1628. /* ellpj.c
  1629. *
  1630. * Jacobian Elliptic Functions
  1631. *
  1632. *
  1633. *
  1634. * SYNOPSIS:
  1635. *
  1636. * double u, m, sn, cn, dn, phi;
  1637. * int ellpj();
  1638. *
  1639. * ellpj( u, m, _&sn, _&cn, _&dn, _&phi );
  1640. *
  1641. *
  1642. *
  1643. * DESCRIPTION:
  1644. *
  1645. *
  1646. * Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
  1647. * and dn(u|m) of parameter m between 0 and 1, and real
  1648. * argument u.
  1649. *
  1650. * These functions are periodic, with quarter-period on the
  1651. * real axis equal to the complete elliptic integral
  1652. * ellpk(1.0-m).
  1653. *
  1654. * Relation to incomplete elliptic integral:
  1655. * If u = ellik(phi,m), then sn(u|m) = sin(phi),
  1656. * and cn(u|m) = cos(phi). Phi is called the amplitude of u.
  1657. *
  1658. * Computation is by means of the arithmetic-geometric mean
  1659. * algorithm, except when m is within 1e-9 of 0 or 1. In the
  1660. * latter case with m close to 1, the approximation applies
  1661. * only for phi < pi/2.
  1662. *
  1663. * ACCURACY:
  1664. *
  1665. * Tested at random points with u between 0 and 10, m between
  1666. * 0 and 1.
  1667. *
  1668. * Absolute error (* = relative error):
  1669. * arithmetic function # trials peak rms
  1670. * DEC sn 1800 4.5e-16 8.7e-17
  1671. * IEEE phi 10000 9.2e-16* 1.4e-16*
  1672. * IEEE sn 50000 4.1e-15 4.6e-16
  1673. * IEEE cn 40000 3.6e-15 4.4e-16
  1674. * IEEE dn 10000 1.3e-12 1.8e-14
  1675. *
  1676. * Peak error observed in consistency check using addition
  1677. * theorem for sn(u+v) was 4e-16 (absolute). Also tested by
  1678. * the above relation to the incomplete elliptic integral.
  1679. * Accuracy deteriorates when u is large.
  1680. *
  1681. */
  1682. /* ellpk.c
  1683. *
  1684. * Complete elliptic integral of the first kind
  1685. *
  1686. *
  1687. *
  1688. * SYNOPSIS:
  1689. *
  1690. * double m1, y, ellpk();
  1691. *
  1692. * y = ellpk( m1 );
  1693. *
  1694. *
  1695. *
  1696. * DESCRIPTION:
  1697. *
  1698. * Approximates the integral
  1699. *
  1700. *
  1701. *
  1702. * pi/2
  1703. * -
  1704. * | |
  1705. * | dt
  1706. * K(m) = | ------------------
  1707. * | 2
  1708. * | | sqrt( 1 - m sin t )
  1709. * -
  1710. * 0
  1711. *
  1712. * where m = 1 - m1, using the approximation
  1713. *
  1714. * P(x) - log x Q(x).
  1715. *
  1716. * The argument m1 is used rather than m so that the logarithmic
  1717. * singularity at m = 1 will be shifted to the origin; this
  1718. * preserves maximum accuracy.
  1719. *
  1720. * K(0) = pi/2.
  1721. *
  1722. * ACCURACY:
  1723. *
  1724. * Relative error:
  1725. * arithmetic domain # trials peak rms
  1726. * DEC 0,1 16000 3.5e-17 1.1e-17
  1727. * IEEE 0,1 30000 2.5e-16 6.8e-17
  1728. *
  1729. * ERROR MESSAGES:
  1730. *
  1731. * message condition value returned
  1732. * ellpk domain x<0, x>1 0.0
  1733. *
  1734. */
  1735. /* euclid.c
  1736. *
  1737. * Rational arithmetic routines
  1738. *
  1739. *
  1740. *
  1741. * SYNOPSIS:
  1742. *
  1743. *
  1744. * typedef struct
  1745. * {
  1746. * double n; numerator
  1747. * double d; denominator
  1748. * }fract;
  1749. *
  1750. * radd( a, b, c ) c = b + a
  1751. * rsub( a, b, c ) c = b - a
  1752. * rmul( a, b, c ) c = b * a
  1753. * rdiv( a, b, c ) c = b / a
  1754. * euclid( &n, &d ) Reduce n/d to lowest terms,
  1755. * return greatest common divisor.
  1756. *
  1757. * Arguments of the routines are pointers to the structures.
  1758. * The double precision numbers are assumed, without checking,
  1759. * to be integer valued. Overflow conditions are reported.
  1760. */
  1761. /* exp.c
  1762. *
  1763. * Exponential function
  1764. *
  1765. *
  1766. *
  1767. * SYNOPSIS:
  1768. *
  1769. * double x, y, exp();
  1770. *
  1771. * y = exp( x );
  1772. *
  1773. *
  1774. *
  1775. * DESCRIPTION:
  1776. *
  1777. * Returns e (2.71828...) raised to the x power.
  1778. *
  1779. * Range reduction is accomplished by separating the argument
  1780. * into an integer k and fraction f such that
  1781. *
  1782. * x k f
  1783. * e = 2 e.
  1784. *
  1785. * A Pade' form 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
  1786. * of degree 2/3 is used to approximate exp(f) in the basic
  1787. * interval [-0.5, 0.5].
  1788. *
  1789. *
  1790. * ACCURACY:
  1791. *
  1792. * Relative error:
  1793. * arithmetic domain # trials peak rms
  1794. * DEC +- 88 50000 2.8e-17 7.0e-18
  1795. * IEEE +- 708 40000 2.0e-16 5.6e-17
  1796. *
  1797. *
  1798. * Error amplification in the exponential function can be
  1799. * a serious matter. The error propagation involves
  1800. * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),
  1801. * which shows that a 1 lsb error in representing X produces
  1802. * a relative error of X times 1 lsb in the function.
  1803. * While the routine gives an accurate result for arguments
  1804. * that are exactly represented by a double precision
  1805. * computer number, the result contains amplified roundoff
  1806. * error for large arguments not exactly represented.
  1807. *
  1808. *
  1809. * ERROR MESSAGES:
  1810. *
  1811. * message condition value returned
  1812. * exp underflow x < MINLOG 0.0
  1813. * exp overflow x > MAXLOG INFINITY
  1814. *
  1815. */
  1816. /* exp10.c
  1817. *
  1818. * Base 10 exponential function
  1819. * (Common antilogarithm)
  1820. *
  1821. *
  1822. *
  1823. * SYNOPSIS:
  1824. *
  1825. * double x, y, exp10();
  1826. *
  1827. * y = exp10( x );
  1828. *
  1829. *
  1830. *
  1831. * DESCRIPTION:
  1832. *
  1833. * Returns 10 raised to the x power.
  1834. *
  1835. * Range reduction is accomplished by expressing the argument
  1836. * as 10**x = 2**n 10**f, with |f| < 0.5 log10(2).
  1837. * The Pade' form
  1838. *
  1839. * 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
  1840. *
  1841. * is used to approximate 10**f.
  1842. *
  1843. *
  1844. *
  1845. * ACCURACY:
  1846. *
  1847. * Relative error:
  1848. * arithmetic domain # trials peak rms
  1849. * IEEE -307,+307 30000 2.2e-16 5.5e-17
  1850. * Test result from an earlier version (2.1):
  1851. * DEC -38,+38 70000 3.1e-17 7.0e-18
  1852. *
  1853. * ERROR MESSAGES:
  1854. *
  1855. * message condition value returned
  1856. * exp10 underflow x < -MAXL10 0.0
  1857. * exp10 overflow x > MAXL10 MAXNUM
  1858. *
  1859. * DEC arithmetic: MAXL10 = 38.230809449325611792.
  1860. * IEEE arithmetic: MAXL10 = 308.2547155599167.
  1861. *
  1862. */
  1863. /* exp2.c
  1864. *
  1865. * Base 2 exponential function
  1866. *
  1867. *
  1868. *
  1869. * SYNOPSIS:
  1870. *
  1871. * double x, y, exp2();
  1872. *
  1873. * y = exp2( x );
  1874. *
  1875. *
  1876. *
  1877. * DESCRIPTION:
  1878. *
  1879. * Returns 2 raised to the x power.
  1880. *
  1881. * Range reduction is accomplished by separating the argument
  1882. * into an integer k and fraction f such that
  1883. * x k f
  1884. * 2 = 2 2.
  1885. *
  1886. * A Pade' form
  1887. *
  1888. * 1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
  1889. *
  1890. * approximates 2**x in the basic range [-0.5, 0.5].
  1891. *
  1892. *
  1893. * ACCURACY:
  1894. *
  1895. * Relative error:
  1896. * arithmetic domain # trials peak rms
  1897. * IEEE -1022,+1024 30000 1.8e-16 5.4e-17
  1898. *
  1899. *
  1900. * See exp.c for comments on error amplification.
  1901. *
  1902. *
  1903. * ERROR MESSAGES:
  1904. *
  1905. * message condition value returned
  1906. * exp underflow x < -MAXL2 0.0
  1907. * exp overflow x > MAXL2 MAXNUM
  1908. *
  1909. * For DEC arithmetic, MAXL2 = 127.
  1910. * For IEEE arithmetic, MAXL2 = 1024.
  1911. */
  1912. /* expn.c
  1913. *
  1914. * Exponential integral En
  1915. *
  1916. *
  1917. *
  1918. * SYNOPSIS:
  1919. *
  1920. * int n;
  1921. * double x, y, expn();
  1922. *
  1923. * y = expn( n, x );
  1924. *
  1925. *
  1926. *
  1927. * DESCRIPTION:
  1928. *
  1929. * Evaluates the exponential integral
  1930. *
  1931. * inf.
  1932. * -
  1933. * | | -xt
  1934. * | e
  1935. * E (x) = | ---- dt.
  1936. * n | n
  1937. * | | t
  1938. * -
  1939. * 1
  1940. *
  1941. *
  1942. * Both n and x must be nonnegative.
  1943. *
  1944. * The routine employs either a power series, a continued
  1945. * fraction, or an asymptotic formula depending on the
  1946. * relative values of n and x.
  1947. *
  1948. * ACCURACY:
  1949. *
  1950. * Relative error:
  1951. * arithmetic domain # trials peak rms
  1952. * DEC 0, 30 5000 2.0e-16 4.6e-17
  1953. * IEEE 0, 30 10000 1.7e-15 3.6e-16
  1954. *
  1955. */
  1956. /* fabs.c
  1957. *
  1958. * Absolute value
  1959. *
  1960. *
  1961. *
  1962. * SYNOPSIS:
  1963. *
  1964. * double x, y;
  1965. *
  1966. * y = fabs( x );
  1967. *
  1968. *
  1969. *
  1970. * DESCRIPTION:
  1971. *
  1972. * Returns the absolute value of the argument.
  1973. *
  1974. */
  1975. /* fac.c
  1976. *
  1977. * Factorial function
  1978. *
  1979. *
  1980. *
  1981. * SYNOPSIS:
  1982. *
  1983. * double y, fac();
  1984. * int i;
  1985. *
  1986. * y = fac( i );
  1987. *
  1988. *
  1989. *
  1990. * DESCRIPTION:
  1991. *
  1992. * Returns factorial of i = 1 * 2 * 3 * ... * i.
  1993. * fac(0) = 1.0.
  1994. *
  1995. * Due to machine arithmetic bounds the largest value of
  1996. * i accepted is 33 in DEC arithmetic or 170 in IEEE
  1997. * arithmetic. Greater values, or negative ones,
  1998. * produce an error message and return MAXNUM.
  1999. *
  2000. *
  2001. *
  2002. * ACCURACY:
  2003. *
  2004. * For i < 34 the values are simply tabulated, and have
  2005. * full machine accuracy. If i > 55, fac(i) = gamma(i+1);
  2006. * see gamma.c.
  2007. *
  2008. * Relative error:
  2009. * arithmetic domain peak
  2010. * IEEE 0, 170 1.4e-15
  2011. * DEC 0, 33 1.4e-17
  2012. *
  2013. */
  2014. /* fdtr.c
  2015. *
  2016. * F distribution
  2017. *
  2018. *
  2019. *
  2020. * SYNOPSIS:
  2021. *
  2022. * int df1, df2;
  2023. * double x, y, fdtr();
  2024. *
  2025. * y = fdtr( df1, df2, x );
  2026. *
  2027. * DESCRIPTION:
  2028. *
  2029. * Returns the area from zero to x under the F density
  2030. * function (also known as Snedcor's density or the
  2031. * variance ratio density). This is the density
  2032. * of x = (u1/df1)/(u2/df2), where u1 and u2 are random
  2033. * variables having Chi square distributions with df1
  2034. * and df2 degrees of freedom, respectively.
  2035. *
  2036. * The incomplete beta integral is used, according to the
  2037. * formula
  2038. *
  2039. * P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
  2040. *
  2041. *
  2042. * The arguments a and b are greater than zero, and x is
  2043. * nonnegative.
  2044. *
  2045. * ACCURACY:
  2046. *
  2047. * Tested at random points (a,b,x).
  2048. *
  2049. * x a,b Relative error:
  2050. * arithmetic domain domain # trials peak rms
  2051. * IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
  2052. * IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
  2053. * IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
  2054. * IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
  2055. * See also incbet.c.
  2056. *
  2057. *
  2058. * ERROR MESSAGES:
  2059. *
  2060. * message condition value returned
  2061. * fdtr domain a<0, b<0, x<0 0.0
  2062. *
  2063. */
  2064. /* fdtrc()
  2065. *
  2066. * Complemented F distribution
  2067. *
  2068. *
  2069. *
  2070. * SYNOPSIS:
  2071. *
  2072. * int df1, df2;
  2073. * double x, y, fdtrc();
  2074. *
  2075. * y = fdtrc( df1, df2, x );
  2076. *
  2077. * DESCRIPTION:
  2078. *
  2079. * Returns the area from x to infinity under the F density
  2080. * function (also known as Snedcor's density or the
  2081. * variance ratio density).
  2082. *
  2083. *
  2084. * inf.
  2085. * -
  2086. * 1 | | a-1 b-1
  2087. * 1-P(x) = ------ | t (1-t) dt
  2088. * B(a,b) | |
  2089. * -
  2090. * x
  2091. *
  2092. *
  2093. * The incomplete beta integral is used, according to the
  2094. * formula
  2095. *
  2096. * P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
  2097. *
  2098. *
  2099. * ACCURACY:
  2100. *
  2101. * Tested at random points (a,b,x) in the indicated intervals.
  2102. * x a,b Relative error:
  2103. * arithmetic domain domain # trials peak rms
  2104. * IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
  2105. * IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
  2106. * IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
  2107. * IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
  2108. * See also incbet.c.
  2109. *
  2110. * ERROR MESSAGES:
  2111. *
  2112. * message condition value returned
  2113. * fdtrc domain a<0, b<0, x<0 0.0
  2114. *
  2115. */
  2116. /* fdtri()
  2117. *
  2118. * Inverse of complemented F distribution
  2119. *
  2120. *
  2121. *
  2122. * SYNOPSIS:
  2123. *
  2124. * int df1, df2;
  2125. * double x, p, fdtri();
  2126. *
  2127. * x = fdtri( df1, df2, p );
  2128. *
  2129. * DESCRIPTION:
  2130. *
  2131. * Finds the F density argument x such that the integral
  2132. * from x to infinity of the F density is equal to the
  2133. * given probability p.
  2134. *
  2135. * This is accomplished using the inverse beta integral
  2136. * function and the relations
  2137. *
  2138. * z = incbi( df2/2, df1/2, p )
  2139. * x = df2 (1-z) / (df1 z).
  2140. *
  2141. * Note: the following relations hold for the inverse of
  2142. * the uncomplemented F distribution:
  2143. *
  2144. * z = incbi( df1/2, df2/2, p )
  2145. * x = df2 z / (df1 (1-z)).
  2146. *
  2147. * ACCURACY:
  2148. *
  2149. * Tested at random points (a,b,p).
  2150. *
  2151. * a,b Relative error:
  2152. * arithmetic domain # trials peak rms
  2153. * For p between .001 and 1:
  2154. * IEEE 1,100 100000 8.3e-15 4.7e-16
  2155. * IEEE 1,10000 100000 2.1e-11 1.4e-13
  2156. * For p between 10^-6 and 10^-3:
  2157. * IEEE 1,100 50000 1.3e-12 8.4e-15
  2158. * IEEE 1,10000 50000 3.0e-12 4.8e-14
  2159. * See also fdtrc.c.
  2160. *
  2161. * ERROR MESSAGES:
  2162. *
  2163. * message condition value returned
  2164. * fdtri domain p <= 0 or p > 1 0.0
  2165. * v < 1
  2166. *
  2167. */
  2168. /* fftr.c
  2169. *
  2170. * FFT of Real Valued Sequence
  2171. *
  2172. *
  2173. *
  2174. * SYNOPSIS:
  2175. *
  2176. * double x[], sine[];
  2177. * int m;
  2178. *
  2179. * fftr( x, m, sine );
  2180. *
  2181. *
  2182. *
  2183. * DESCRIPTION:
  2184. *
  2185. * Computes the (complex valued) discrete Fourier transform of
  2186. * the real valued sequence x[]. The input sequence x[] contains
  2187. * n = 2**m samples. The program fills array sine[k] with
  2188. * n/4 + 1 values of sin( 2 PI k / n ).
  2189. *
  2190. * Data format for complex valued output is real part followed
  2191. * by imaginary part. The output is developed in the input
  2192. * array x[].
  2193. *
  2194. * The algorithm takes advantage of the fact that the FFT of an
  2195. * n point real sequence can be obtained from an n/2 point
  2196. * complex FFT.
  2197. *
  2198. * A radix 2 FFT algorithm is used.
  2199. *
  2200. * Execution time on an LSI-11/23 with floating point chip
  2201. * is 1.0 sec for n = 256.
  2202. *
  2203. *
  2204. *
  2205. * REFERENCE:
  2206. *
  2207. * E. Oran Brigham, The Fast Fourier Transform;
  2208. * Prentice-Hall, Inc., 1974
  2209. *
  2210. */
  2211. /* ceil()
  2212. * floor()
  2213. * frexp()
  2214. * ldexp()
  2215. * signbit()
  2216. * isnan()
  2217. * isfinite()
  2218. *
  2219. * Floating point numeric utilities
  2220. *
  2221. *
  2222. *
  2223. * SYNOPSIS:
  2224. *
  2225. * double ceil(), floor(), frexp(), ldexp();
  2226. * int signbit(), isnan(), isfinite();
  2227. * double x, y;
  2228. * int expnt, n;
  2229. *
  2230. * y = floor(x);
  2231. * y = ceil(x);
  2232. * y = frexp( x, &expnt );
  2233. * y = ldexp( x, n );
  2234. * n = signbit(x);
  2235. * n = isnan(x);
  2236. * n = isfinite(x);
  2237. *
  2238. *
  2239. *
  2240. * DESCRIPTION:
  2241. *
  2242. * All four routines return a double precision floating point
  2243. * result.
  2244. *
  2245. * floor() returns the largest integer less than or equal to x.
  2246. * It truncates toward minus infinity.
  2247. *
  2248. * ceil() returns the smallest integer greater than or equal
  2249. * to x. It truncates toward plus infinity.
  2250. *
  2251. * frexp() extracts the exponent from x. It returns an integer
  2252. * power of two to expnt and the significand between 0.5 and 1
  2253. * to y. Thus x = y * 2**expn.
  2254. *
  2255. * ldexp() multiplies x by 2**n.
  2256. *
  2257. * signbit(x) returns 1 if the sign bit of x is 1, else 0.
  2258. *
  2259. * These functions are part of the standard C run time library
  2260. * for many but not all C compilers. The ones supplied are
  2261. * written in C for either DEC or IEEE arithmetic. They should
  2262. * be used only if your compiler library does not already have
  2263. * them.
  2264. *
  2265. * The IEEE versions assume that denormal numbers are implemented
  2266. * in the arithmetic. Some modifications will be required if
  2267. * the arithmetic has abrupt rather than gradual underflow.
  2268. */
  2269. /* fresnl.c
  2270. *
  2271. * Fresnel integral
  2272. *
  2273. *
  2274. *
  2275. * SYNOPSIS:
  2276. *
  2277. * double x, S, C;
  2278. * void fresnl();
  2279. *
  2280. * fresnl( x, _&S, _&C );
  2281. *
  2282. *
  2283. * DESCRIPTION:
  2284. *
  2285. * Evaluates the Fresnel integrals
  2286. *
  2287. * x
  2288. * -
  2289. * | |
  2290. * C(x) = | cos(pi/2 t**2) dt,
  2291. * | |
  2292. * -
  2293. * 0
  2294. *
  2295. * x
  2296. * -
  2297. * | |
  2298. * S(x) = | sin(pi/2 t**2) dt.
  2299. * | |
  2300. * -
  2301. * 0
  2302. *
  2303. *
  2304. * The integrals are evaluated by a power series for x < 1.
  2305. * For x >= 1 auxiliary functions f(x) and g(x) are employed
  2306. * such that
  2307. *
  2308. * C(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 )
  2309. * S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 )
  2310. *
  2311. *
  2312. *
  2313. * ACCURACY:
  2314. *
  2315. * Relative error.
  2316. *
  2317. * Arithmetic function domain # trials peak rms
  2318. * IEEE S(x) 0, 10 10000 2.0e-15 3.2e-16
  2319. * IEEE C(x) 0, 10 10000 1.8e-15 3.3e-16
  2320. * DEC S(x) 0, 10 6000 2.2e-16 3.9e-17
  2321. * DEC C(x) 0, 10 5000 2.3e-16 3.9e-17
  2322. */
  2323. /* gamma.c
  2324. *
  2325. * Gamma function
  2326. *
  2327. *
  2328. *
  2329. * SYNOPSIS:
  2330. *
  2331. * double x, y, gamma();
  2332. * extern int sgngam;
  2333. *
  2334. * y = gamma( x );
  2335. *
  2336. *
  2337. *
  2338. * DESCRIPTION:
  2339. *
  2340. * Returns gamma function of the argument. The result is
  2341. * correctly signed, and the sign (+1 or -1) is also
  2342. * returned in a global (extern) variable named sgngam.
  2343. * This variable is also filled in by the logarithmic gamma
  2344. * function lgam().
  2345. *
  2346. * Arguments |x| <= 34 are reduced by recurrence and the function
  2347. * approximated by a rational function of degree 6/7 in the
  2348. * interval (2,3). Large arguments are handled by Stirling's
  2349. * formula. Large negative arguments are made positive using
  2350. * a reflection formula.
  2351. *
  2352. *
  2353. * ACCURACY:
  2354. *
  2355. * Relative error:
  2356. * arithmetic domain # trials peak rms
  2357. * DEC -34, 34 10000 1.3e-16 2.5e-17
  2358. * IEEE -170,-33 20000 2.3e-15 3.3e-16
  2359. * IEEE -33, 33 20000 9.4e-16 2.2e-16
  2360. * IEEE 33, 171.6 20000 2.3e-15 3.2e-16
  2361. *
  2362. * Error for arguments outside the test range will be larger
  2363. * owing to error amplification by the exponential function.
  2364. *
  2365. */
  2366. /* lgam()
  2367. *
  2368. * Natural logarithm of gamma function
  2369. *
  2370. *
  2371. *
  2372. * SYNOPSIS:
  2373. *
  2374. * double x, y, lgam();
  2375. * extern int sgngam;
  2376. *
  2377. * y = lgam( x );
  2378. *
  2379. *
  2380. *
  2381. * DESCRIPTION:
  2382. *
  2383. * Returns the base e (2.718...) logarithm of the absolute
  2384. * value of the gamma function of the argument.
  2385. * The sign (+1 or -1) of the gamma function is returned in a
  2386. * global (extern) variable named sgngam.
  2387. *
  2388. * For arguments greater than 13, the logarithm of the gamma
  2389. * function is approximated by the logarithmic version of
  2390. * Stirling's formula using a polynomial approximation of
  2391. * degree 4. Arguments between -33 and +33 are reduced by
  2392. * recurrence to the interval [2,3] of a rational approximation.
  2393. * The cosecant reflection formula is employed for arguments
  2394. * less than -33.
  2395. *
  2396. * Arguments greater than MAXLGM return MAXNUM and an error
  2397. * message. MAXLGM = 2.035093e36 for DEC
  2398. * arithmetic or 2.556348e305 for IEEE arithmetic.
  2399. *
  2400. *
  2401. *
  2402. * ACCURACY:
  2403. *
  2404. *
  2405. * arithmetic domain # trials peak rms
  2406. * DEC 0, 3 7000 5.2e-17 1.3e-17
  2407. * DEC 2.718, 2.035e36 5000 3.9e-17 9.9e-18
  2408. * IEEE 0, 3 28000 5.4e-16 1.1e-16
  2409. * IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17
  2410. * The error criterion was relative when the function magnitude
  2411. * was greater than one but absolute when it was less than one.
  2412. *
  2413. * The following test used the relative error criterion, though
  2414. * at certain points the relative error could be much higher than
  2415. * indicated.
  2416. * IEEE -200, -4 10000 4.8e-16 1.3e-16
  2417. *
  2418. */
  2419. /* gdtr.c
  2420. *
  2421. * Gamma distribution function
  2422. *
  2423. *
  2424. *
  2425. * SYNOPSIS:
  2426. *
  2427. * double a, b, x, y, gdtr();
  2428. *
  2429. * y = gdtr( a, b, x );
  2430. *
  2431. *
  2432. *
  2433. * DESCRIPTION:
  2434. *
  2435. * Returns the integral from zero to x of the gamma probability
  2436. * density function:
  2437. *
  2438. *
  2439. * x
  2440. * b -
  2441. * a | | b-1 -at
  2442. * y = ----- | t e dt
  2443. * - | |
  2444. * | (b) -
  2445. * 0
  2446. *
  2447. * The incomplete gamma integral is used, according to the
  2448. * relation
  2449. *
  2450. * y = igam( b, ax ).
  2451. *
  2452. *
  2453. * ACCURACY:
  2454. *
  2455. * See igam().
  2456. *
  2457. * ERROR MESSAGES:
  2458. *
  2459. * message condition value returned
  2460. * gdtr domain x < 0 0.0
  2461. *
  2462. */
  2463. /* gdtrc.c
  2464. *
  2465. * Complemented gamma distribution function
  2466. *
  2467. *
  2468. *
  2469. * SYNOPSIS:
  2470. *
  2471. * double a, b, x, y, gdtrc();
  2472. *
  2473. * y = gdtrc( a, b, x );
  2474. *
  2475. *
  2476. *
  2477. * DESCRIPTION:
  2478. *
  2479. * Returns the integral from x to infinity of the gamma
  2480. * probability density function:
  2481. *
  2482. *
  2483. * inf.
  2484. * b -
  2485. * a | | b-1 -at
  2486. * y = ----- | t e dt
  2487. * - | |
  2488. * | (b) -
  2489. * x
  2490. *
  2491. * The incomplete gamma integral is used, according to the
  2492. * relation
  2493. *
  2494. * y = igamc( b, ax ).
  2495. *
  2496. *
  2497. * ACCURACY:
  2498. *
  2499. * See igamc().
  2500. *
  2501. * ERROR MESSAGES:
  2502. *
  2503. * message condition value returned
  2504. * gdtrc domain x < 0 0.0
  2505. *
  2506. */
  2507. /*
  2508. C
  2509. C ..................................................................
  2510. C
  2511. C SUBROUTINE GELS
  2512. C
  2513. C PURPOSE
  2514. C TO SOLVE A SYSTEM OF SIMULTANEOUS LINEAR EQUATIONS WITH
  2515. C SYMMETRIC COEFFICIENT MATRIX UPPER TRIANGULAR PART OF WHICH
  2516. C IS ASSUMED TO BE STORED COLUMNWISE.
  2517. C
  2518. C USAGE
  2519. C CALL GELS(R,A,M,N,EPS,IER,AUX)
  2520. C
  2521. C DESCRIPTION OF PARAMETERS
  2522. C R - M BY N RIGHT HAND SIDE MATRIX. (DESTROYED)
  2523. C ON RETURN R CONTAINS THE SOLUTION OF THE EQUATIONS.
  2524. C A - UPPER TRIANGULAR PART OF THE SYMMETRIC
  2525. C M BY M COEFFICIENT MATRIX. (DESTROYED)
  2526. C M - THE NUMBER OF EQUATIONS IN THE SYSTEM.
  2527. C N - THE NUMBER OF RIGHT HAND SIDE VECTORS.
  2528. C EPS - AN INPUT CONSTANT WHICH IS USED AS RELATIVE
  2529. C TOLERANCE FOR TEST ON LOSS OF SIGNIFICANCE.
  2530. C IER - RESULTING ERROR PARAMETER CODED AS FOLLOWS
  2531. C IER=0 - NO ERROR,
  2532. C IER=-1 - NO RESULT BECAUSE OF M LESS THAN 1 OR
  2533. C PIVOT ELEMENT AT ANY ELIMINATION STEP
  2534. C EQUAL TO 0,
  2535. C IER=K - WARNING DUE TO POSSIBLE LOSS OF SIGNIFI-
  2536. C CANCE INDICATED AT ELIMINATION STEP K+1,
  2537. C WHERE PIVOT ELEMENT WAS LESS THAN OR
  2538. C EQUAL TO THE INTERNAL TOLERANCE EPS TIMES
  2539. C ABSOLUTELY GREATEST MAIN DIAGONAL
  2540. C ELEMENT OF MATRIX A.
  2541. C AUX - AN AUXILIARY STORAGE ARRAY WITH DIMENSION M-1.
  2542. C
  2543. C REMARKS
  2544. C UPPER TRIANGULAR PART OF MATRIX A IS ASSUMED TO BE STORED
  2545. C COLUMNWISE IN M*(M+1)/2 SUCCESSIVE STORAGE LOCATIONS, RIGHT
  2546. C HAND SIDE MATRIX R COLUMNWISE IN N*M SUCCESSIVE STORAGE
  2547. C LOCATIONS. ON RETURN SOLUTION MATRIX R IS STORED COLUMNWISE
  2548. C TOO.
  2549. C THE PROCEDURE GIVES RESULTS IF THE NUMBER OF EQUATIONS M IS
  2550. C GREATER THAN 0 AND PIVOT ELEMENTS AT ALL ELIMINATION STEPS
  2551. C ARE DIFFERENT FROM 0. HOWEVER WARNING IER=K - IF GIVEN -
  2552. C INDICATES POSSIBLE LOSS OF SIGNIFICANCE. IN CASE OF A WELL
  2553. C SCALED MATRIX A AND APPROPRIATE TOLERANCE EPS, IER=K MAY BE
  2554. C INTERPRETED THAT MATRIX A HAS THE RANK K. NO WARNING IS
  2555. C GIVEN IN CASE M=1.
  2556. C ERROR PARAMETER IER=-1 DOES NOT NECESSARILY MEAN THAT
  2557. C MATRIX A IS SINGULAR, AS ONLY MAIN DIAGONAL ELEMENTS
  2558. C ARE USED AS PIVOT ELEMENTS. POSSIBLY SUBROUTINE GELG (WHICH
  2559. C WORKS WITH TOTAL PIVOTING) WOULD BE ABLE TO FIND A SOLUTION.
  2560. C
  2561. C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
  2562. C NONE
  2563. C
  2564. C METHOD
  2565. C SOLUTION IS DONE BY MEANS OF GAUSS-ELIMINATION WITH
  2566. C PIVOTING IN MAIN DIAGONAL, IN ORDER TO PRESERVE
  2567. C SYMMETRY IN REMAINING COEFFICIENT MATRICES.
  2568. C
  2569. C ..................................................................
  2570. C
  2571. */
  2572. /* hyp2f1.c
  2573. *
  2574. * Gauss hypergeometric function F
  2575. * 2 1
  2576. *
  2577. *
  2578. * SYNOPSIS:
  2579. *
  2580. * double a, b, c, x, y, hyp2f1();
  2581. *
  2582. * y = hyp2f1( a, b, c, x );
  2583. *
  2584. *
  2585. * DESCRIPTION:
  2586. *
  2587. *
  2588. * hyp2f1( a, b, c, x ) = F ( a, b; c; x )
  2589. * 2 1
  2590. *
  2591. * inf.
  2592. * - a(a+1)...(a+k) b(b+1)...(b+k) k+1
  2593. * = 1 + > ----------------------------- x .
  2594. * - c(c+1)...(c+k) (k+1)!
  2595. * k = 0
  2596. *
  2597. * Cases addressed are
  2598. * Tests and escapes for negative integer a, b, or c
  2599. * Linear transformation if c - a or c - b negative integer
  2600. * Special case c = a or c = b
  2601. * Linear transformation for x near +1
  2602. * Transformation for x < -0.5
  2603. * Psi function expansion if x > 0.5 and c - a - b integer
  2604. * Conditionally, a recurrence on c to make c-a-b > 0
  2605. *
  2606. * |x| > 1 is rejected.
  2607. *
  2608. * The parameters a, b, c are considered to be integer
  2609. * valued if they are within 1.0e-14 of the nearest integer
  2610. * (1.0e-13 for IEEE arithmetic).
  2611. *
  2612. * ACCURACY:
  2613. *
  2614. *
  2615. * Relative error (-1 < x < 1):
  2616. * arithmetic domain # trials peak rms
  2617. * IEEE -1,7 230000 1.2e-11 5.2e-14
  2618. *
  2619. * Several special cases also tested with a, b, c in
  2620. * the range -7 to 7.
  2621. *
  2622. * ERROR MESSAGES:
  2623. *
  2624. * A "partial loss of precision" message is printed if
  2625. * the internally estimated relative error exceeds 1^-12.
  2626. * A "singularity" message is printed on overflow or
  2627. * in cases not addressed (such as x < -1).
  2628. */
  2629. /* hyperg.c
  2630. *
  2631. * Confluent hypergeometric function
  2632. *
  2633. *
  2634. *
  2635. * SYNOPSIS:
  2636. *
  2637. * double a, b, x, y, hyperg();
  2638. *
  2639. * y = hyperg( a, b, x );
  2640. *
  2641. *
  2642. *
  2643. * DESCRIPTION:
  2644. *
  2645. * Computes the confluent hypergeometric function
  2646. *
  2647. * 1 2
  2648. * a x a(a+1) x
  2649. * F ( a,b;x ) = 1 + ---- + --------- + ...
  2650. * 1 1 b 1! b(b+1) 2!
  2651. *
  2652. * Many higher transcendental functions are special cases of
  2653. * this power series.
  2654. *
  2655. * As is evident from the formula, b must not be a negative
  2656. * integer or zero unless a is an integer with 0 >= a > b.
  2657. *
  2658. * The routine attempts both a direct summation of the series
  2659. * and an asymptotic expansion. In each case error due to
  2660. * roundoff, cancellation, and nonconvergence is estimated.
  2661. * The result with smaller estimated error is returned.
  2662. *
  2663. *
  2664. *
  2665. * ACCURACY:
  2666. *
  2667. * Tested at random points (a, b, x), all three variables
  2668. * ranging from 0 to 30.
  2669. * Relative error:
  2670. * arithmetic domain # trials peak rms
  2671. * DEC 0,30 2000 1.2e-15 1.3e-16
  2672. * IEEE 0,30 30000 1.8e-14 1.1e-15
  2673. *
  2674. * Larger errors can be observed when b is near a negative
  2675. * integer or zero. Certain combinations of arguments yield
  2676. * serious cancellation error in the power series summation
  2677. * and also are not in the region of near convergence of the
  2678. * asymptotic series. An error message is printed if the
  2679. * self-estimated relative error is greater than 1.0e-12.
  2680. *
  2681. */
  2682. /* i0.c
  2683. *
  2684. * Modified Bessel function of order zero
  2685. *
  2686. *
  2687. *
  2688. * SYNOPSIS:
  2689. *
  2690. * double x, y, i0();
  2691. *
  2692. * y = i0( x );
  2693. *
  2694. *
  2695. *
  2696. * DESCRIPTION:
  2697. *
  2698. * Returns modified Bessel function of order zero of the
  2699. * argument.
  2700. *
  2701. * The function is defined as i0(x) = j0( ix ).
  2702. *
  2703. * The range is partitioned into the two intervals [0,8] and
  2704. * (8, infinity). Chebyshev polynomial expansions are employed
  2705. * in each interval.
  2706. *
  2707. *
  2708. *
  2709. * ACCURACY:
  2710. *
  2711. * Relative error:
  2712. * arithmetic domain # trials peak rms
  2713. * DEC 0,30 6000 8.2e-17 1.9e-17
  2714. * IEEE 0,30 30000 5.8e-16 1.4e-16
  2715. *
  2716. */
  2717. /* i0e.c
  2718. *
  2719. * Modified Bessel function of order zero,
  2720. * exponentially scaled
  2721. *
  2722. *
  2723. *
  2724. * SYNOPSIS:
  2725. *
  2726. * double x, y, i0e();
  2727. *
  2728. * y = i0e( x );
  2729. *
  2730. *
  2731. *
  2732. * DESCRIPTION:
  2733. *
  2734. * Returns exponentially scaled modified Bessel function
  2735. * of order zero of the argument.
  2736. *
  2737. * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
  2738. *
  2739. *
  2740. *
  2741. * ACCURACY:
  2742. *
  2743. * Relative error:
  2744. * arithmetic domain # trials peak rms
  2745. * IEEE 0,30 30000 5.4e-16 1.2e-16
  2746. * See i0().
  2747. *
  2748. */
  2749. /* i1.c
  2750. *
  2751. * Modified Bessel function of order one
  2752. *
  2753. *
  2754. *
  2755. * SYNOPSIS:
  2756. *
  2757. * double x, y, i1();
  2758. *
  2759. * y = i1( x );
  2760. *
  2761. *
  2762. *
  2763. * DESCRIPTION:
  2764. *
  2765. * Returns modified Bessel function of order one of the
  2766. * argument.
  2767. *
  2768. * The function is defined as i1(x) = -i j1( ix ).
  2769. *
  2770. * The range is partitioned into the two intervals [0,8] and
  2771. * (8, infinity). Chebyshev polynomial expansions are employed
  2772. * in each interval.
  2773. *
  2774. *
  2775. *
  2776. * ACCURACY:
  2777. *
  2778. * Relative error:
  2779. * arithmetic domain # trials peak rms
  2780. * DEC 0, 30 3400 1.2e-16 2.3e-17
  2781. * IEEE 0, 30 30000 1.9e-15 2.1e-16
  2782. *
  2783. *
  2784. */
  2785. /* i1e.c
  2786. *
  2787. * Modified Bessel function of order one,
  2788. * exponentially scaled
  2789. *
  2790. *
  2791. *
  2792. * SYNOPSIS:
  2793. *
  2794. * double x, y, i1e();
  2795. *
  2796. * y = i1e( x );
  2797. *
  2798. *
  2799. *
  2800. * DESCRIPTION:
  2801. *
  2802. * Returns exponentially scaled modified Bessel function
  2803. * of order one of the argument.
  2804. *
  2805. * The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
  2806. *
  2807. *
  2808. *
  2809. * ACCURACY:
  2810. *
  2811. * Relative error:
  2812. * arithmetic domain # trials peak rms
  2813. * IEEE 0, 30 30000 2.0e-15 2.0e-16
  2814. * See i1().
  2815. *
  2816. */
  2817. /* igam.c
  2818. *
  2819. * Incomplete gamma integral
  2820. *
  2821. *
  2822. *
  2823. * SYNOPSIS:
  2824. *
  2825. * double a, x, y, igam();
  2826. *
  2827. * y = igam( a, x );
  2828. *
  2829. * DESCRIPTION:
  2830. *
  2831. * The function is defined by
  2832. *
  2833. * x
  2834. * -
  2835. * 1 | | -t a-1
  2836. * igam(a,x) = ----- | e t dt.
  2837. * - | |
  2838. * | (a) -
  2839. * 0
  2840. *
  2841. *
  2842. * In this implementation both arguments must be positive.
  2843. * The integral is evaluated by either a power series or
  2844. * continued fraction expansion, depending on the relative
  2845. * values of a and x.
  2846. *
  2847. * ACCURACY:
  2848. *
  2849. * Relative error:
  2850. * arithmetic domain # trials peak rms
  2851. * IEEE 0,30 200000 3.6e-14 2.9e-15
  2852. * IEEE 0,100 300000 9.9e-14 1.5e-14
  2853. */
  2854. /* igamc()
  2855. *
  2856. * Complemented incomplete gamma integral
  2857. *
  2858. *
  2859. *
  2860. * SYNOPSIS:
  2861. *
  2862. * double a, x, y, igamc();
  2863. *
  2864. * y = igamc( a, x );
  2865. *
  2866. * DESCRIPTION:
  2867. *
  2868. * The function is defined by
  2869. *
  2870. *
  2871. * igamc(a,x) = 1 - igam(a,x)
  2872. *
  2873. * inf.
  2874. * -
  2875. * 1 | | -t a-1
  2876. * = ----- | e t dt.
  2877. * - | |
  2878. * | (a) -
  2879. * x
  2880. *
  2881. *
  2882. * In this implementation both arguments must be positive.
  2883. * The integral is evaluated by either a power series or
  2884. * continued fraction expansion, depending on the relative
  2885. * values of a and x.
  2886. *
  2887. * ACCURACY:
  2888. *
  2889. * Tested at random a, x.
  2890. * a x Relative error:
  2891. * arithmetic domain domain # trials peak rms
  2892. * IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
  2893. * IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
  2894. */
  2895. /* igami()
  2896. *
  2897. * Inverse of complemented imcomplete gamma integral
  2898. *
  2899. *
  2900. *
  2901. * SYNOPSIS:
  2902. *
  2903. * double a, x, p, igami();
  2904. *
  2905. * x = igami( a, p );
  2906. *
  2907. * DESCRIPTION:
  2908. *
  2909. * Given p, the function finds x such that
  2910. *
  2911. * igamc( a, x ) = p.
  2912. *
  2913. * Starting with the approximate value
  2914. *
  2915. * 3
  2916. * x = a t
  2917. *
  2918. * where
  2919. *
  2920. * t = 1 - d - ndtri(p) sqrt(d)
  2921. *
  2922. * and
  2923. *
  2924. * d = 1/9a,
  2925. *
  2926. * the routine performs up to 10 Newton iterations to find the
  2927. * root of igamc(a,x) - p = 0.
  2928. *
  2929. * ACCURACY:
  2930. *
  2931. * Tested at random a, p in the intervals indicated.
  2932. *
  2933. * a p Relative error:
  2934. * arithmetic domain domain # trials peak rms
  2935. * IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
  2936. * IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
  2937. * IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
  2938. */
  2939. /* incbet.c
  2940. *
  2941. * Incomplete beta integral
  2942. *
  2943. *
  2944. * SYNOPSIS:
  2945. *
  2946. * double a, b, x, y, incbet();
  2947. *
  2948. * y = incbet( a, b, x );
  2949. *
  2950. *
  2951. * DESCRIPTION:
  2952. *
  2953. * Returns incomplete beta integral of the arguments, evaluated
  2954. * from zero to x. The function is defined as
  2955. *
  2956. * x
  2957. * - -
  2958. * | (a+b) | | a-1 b-1
  2959. * ----------- | t (1-t) dt.
  2960. * - - | |
  2961. * | (a) | (b) -
  2962. * 0
  2963. *
  2964. * The domain of definition is 0 <= x <= 1. In this
  2965. * implementation a and b are restricted to positive values.
  2966. * The integral from x to 1 may be obtained by the symmetry
  2967. * relation
  2968. *
  2969. * 1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
  2970. *
  2971. * The integral is evaluated by a continued fraction expansion
  2972. * or, when b*x is small, by a power series.
  2973. *
  2974. * ACCURACY:
  2975. *
  2976. * Tested at uniformly distributed random points (a,b,x) with a and b
  2977. * in "domain" and x between 0 and 1.
  2978. * Relative error
  2979. * arithmetic domain # trials peak rms
  2980. * IEEE 0,5 10000 6.9e-15 4.5e-16
  2981. * IEEE 0,85 250000 2.2e-13 1.7e-14
  2982. * IEEE 0,1000 30000 5.3e-12 6.3e-13
  2983. * IEEE 0,10000 250000 9.3e-11 7.1e-12
  2984. * IEEE 0,100000 10000 8.7e-10 4.8e-11
  2985. * Outputs smaller than the IEEE gradual underflow threshold
  2986. * were excluded from these statistics.
  2987. *
  2988. * ERROR MESSAGES:
  2989. * message condition value returned
  2990. * incbet domain x<0, x>1 0.0
  2991. * incbet underflow 0.0
  2992. */
  2993. /* incbi()
  2994. *
  2995. * Inverse of imcomplete beta integral
  2996. *
  2997. *
  2998. *
  2999. * SYNOPSIS:
  3000. *
  3001. * double a, b, x, y, incbi();
  3002. *
  3003. * x = incbi( a, b, y );
  3004. *
  3005. *
  3006. *
  3007. * DESCRIPTION:
  3008. *
  3009. * Given y, the function finds x such that
  3010. *
  3011. * incbet( a, b, x ) = y .
  3012. *
  3013. * The routine performs interval halving or Newton iterations to find the
  3014. * root of incbet(a,b,x) - y = 0.
  3015. *
  3016. *
  3017. * ACCURACY:
  3018. *
  3019. * Relative error:
  3020. * x a,b
  3021. * arithmetic domain domain # trials peak rms
  3022. * IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
  3023. * IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
  3024. * IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
  3025. * VAX 0,1 .5,100 25000 3.5e-14 1.1e-15
  3026. * With a and b constrained to half-integer or integer values:
  3027. * IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
  3028. * IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
  3029. * With a = .5, b constrained to half-integer or integer values:
  3030. * IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
  3031. */
  3032. /* iv.c
  3033. *
  3034. * Modified Bessel function of noninteger order
  3035. *
  3036. *
  3037. *
  3038. * SYNOPSIS:
  3039. *
  3040. * double v, x, y, iv();
  3041. *
  3042. * y = iv( v, x );
  3043. *
  3044. *
  3045. *
  3046. * DESCRIPTION:
  3047. *
  3048. * Returns modified Bessel function of order v of the
  3049. * argument. If x is negative, v must be integer valued.
  3050. *
  3051. * The function is defined as Iv(x) = Jv( ix ). It is
  3052. * here computed in terms of the confluent hypergeometric
  3053. * function, according to the formula
  3054. *
  3055. * v -x
  3056. * Iv(x) = (x/2) e hyperg( v+0.5, 2v+1, 2x ) / gamma(v+1)
  3057. *
  3058. * If v is a negative integer, then v is replaced by -v.
  3059. *
  3060. *
  3061. * ACCURACY:
  3062. *
  3063. * Tested at random points (v, x), with v between 0 and
  3064. * 30, x between 0 and 28.
  3065. * Relative error:
  3066. * arithmetic domain # trials peak rms
  3067. * DEC 0,30 2000 3.1e-15 5.4e-16
  3068. * IEEE 0,30 10000 1.7e-14 2.7e-15
  3069. *
  3070. * Accuracy is diminished if v is near a negative integer.
  3071. *
  3072. * See also hyperg.c.
  3073. *
  3074. */
  3075. /* j0.c
  3076. *
  3077. * Bessel function of order zero
  3078. *
  3079. *
  3080. *
  3081. * SYNOPSIS:
  3082. *
  3083. * double x, y, j0();
  3084. *
  3085. * y = j0( x );
  3086. *
  3087. *
  3088. *
  3089. * DESCRIPTION:
  3090. *
  3091. * Returns Bessel function of order zero of the argument.
  3092. *
  3093. * The domain is divided into the intervals [0, 5] and
  3094. * (5, infinity). In the first interval the following rational
  3095. * approximation is used:
  3096. *
  3097. *
  3098. * 2 2
  3099. * (w - r ) (w - r ) P (w) / Q (w)
  3100. * 1 2 3 8
  3101. *
  3102. * 2
  3103. * where w = x and the two r's are zeros of the function.
  3104. *
  3105. * In the second interval, the Hankel asymptotic expansion
  3106. * is employed with two rational functions of degree 6/6
  3107. * and 7/7.
  3108. *
  3109. *
  3110. *
  3111. * ACCURACY:
  3112. *
  3113. * Absolute error:
  3114. * arithmetic domain # trials peak rms
  3115. * DEC 0, 30 10000 4.4e-17 6.3e-18
  3116. * IEEE 0, 30 60000 4.2e-16 1.1e-16
  3117. *
  3118. */
  3119. /* y0.c
  3120. *
  3121. * Bessel function of the second kind, order zero
  3122. *
  3123. *
  3124. *
  3125. * SYNOPSIS:
  3126. *
  3127. * double x, y, y0();
  3128. *
  3129. * y = y0( x );
  3130. *
  3131. *
  3132. *
  3133. * DESCRIPTION:
  3134. *
  3135. * Returns Bessel function of the second kind, of order
  3136. * zero, of the argument.
  3137. *
  3138. * The domain is divided into the intervals [0, 5] and
  3139. * (5, infinity). In the first interval a rational approximation
  3140. * R(x) is employed to compute
  3141. * y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
  3142. * Thus a call to j0() is required.
  3143. *
  3144. * In the second interval, the Hankel asymptotic expansion
  3145. * is employed with two rational functions of degree 6/6
  3146. * and 7/7.
  3147. *
  3148. *
  3149. *
  3150. * ACCURACY:
  3151. *
  3152. * Absolute error, when y0(x) < 1; else relative error:
  3153. *
  3154. * arithmetic domain # trials peak rms
  3155. * DEC 0, 30 9400 7.0e-17 7.9e-18
  3156. * IEEE 0, 30 30000 1.3e-15 1.6e-16
  3157. *
  3158. */
  3159. /* j1.c
  3160. *
  3161. * Bessel function of order one
  3162. *
  3163. *
  3164. *
  3165. * SYNOPSIS:
  3166. *
  3167. * double x, y, j1();
  3168. *
  3169. * y = j1( x );
  3170. *
  3171. *
  3172. *
  3173. * DESCRIPTION:
  3174. *
  3175. * Returns Bessel function of order one of the argument.
  3176. *
  3177. * The domain is divided into the intervals [0, 8] and
  3178. * (8, infinity). In the first interval a 24 term Chebyshev
  3179. * expansion is used. In the second, the asymptotic
  3180. * trigonometric representation is employed using two
  3181. * rational functions of degree 5/5.
  3182. *
  3183. *
  3184. *
  3185. * ACCURACY:
  3186. *
  3187. * Absolute error:
  3188. * arithmetic domain # trials peak rms
  3189. * DEC 0, 30 10000 4.0e-17 1.1e-17
  3190. * IEEE 0, 30 30000 2.6e-16 1.1e-16
  3191. *
  3192. *
  3193. */
  3194. /* y1.c
  3195. *
  3196. * Bessel function of second kind of order one
  3197. *
  3198. *
  3199. *
  3200. * SYNOPSIS:
  3201. *
  3202. * double x, y, y1();
  3203. *
  3204. * y = y1( x );
  3205. *
  3206. *
  3207. *
  3208. * DESCRIPTION:
  3209. *
  3210. * Returns Bessel function of the second kind of order one
  3211. * of the argument.
  3212. *
  3213. * The domain is divided into the intervals [0, 8] and
  3214. * (8, infinity). In the first interval a 25 term Chebyshev
  3215. * expansion is used, and a call to j1() is required.
  3216. * In the second, the asymptotic trigonometric representation
  3217. * is employed using two rational functions of degree 5/5.
  3218. *
  3219. *
  3220. *
  3221. * ACCURACY:
  3222. *
  3223. * Absolute error:
  3224. * arithmetic domain # trials peak rms
  3225. * DEC 0, 30 10000 8.6e-17 1.3e-17
  3226. * IEEE 0, 30 30000 1.0e-15 1.3e-16
  3227. *
  3228. * (error criterion relative when |y1| > 1).
  3229. *
  3230. */
  3231. /* jn.c
  3232. *
  3233. * Bessel function of integer order
  3234. *
  3235. *
  3236. *
  3237. * SYNOPSIS:
  3238. *
  3239. * int n;
  3240. * double x, y, jn();
  3241. *
  3242. * y = jn( n, x );
  3243. *
  3244. *
  3245. *
  3246. * DESCRIPTION:
  3247. *
  3248. * Returns Bessel function of order n, where n is a
  3249. * (possibly negative) integer.
  3250. *
  3251. * The ratio of jn(x) to j0(x) is computed by backward
  3252. * recurrence. First the ratio jn/jn-1 is found by a
  3253. * continued fraction expansion. Then the recurrence
  3254. * relating successive orders is applied until j0 or j1 is
  3255. * reached.
  3256. *
  3257. * If n = 0 or 1 the routine for j0 or j1 is called
  3258. * directly.
  3259. *
  3260. *
  3261. *
  3262. * ACCURACY:
  3263. *
  3264. * Absolute error:
  3265. * arithmetic range # trials peak rms
  3266. * DEC 0, 30 5500 6.9e-17 9.3e-18
  3267. * IEEE 0, 30 5000 4.4e-16 7.9e-17
  3268. *
  3269. *
  3270. * Not suitable for large n or x. Use jv() instead.
  3271. *
  3272. */
  3273. /* jv.c
  3274. *
  3275. * Bessel function of noninteger order
  3276. *
  3277. *
  3278. *
  3279. * SYNOPSIS:
  3280. *
  3281. * double v, x, y, jv();
  3282. *
  3283. * y = jv( v, x );
  3284. *
  3285. *
  3286. *
  3287. * DESCRIPTION:
  3288. *
  3289. * Returns Bessel function of order v of the argument,
  3290. * where v is real. Negative x is allowed if v is an integer.
  3291. *
  3292. * Several expansions are included: the ascending power
  3293. * series, the Hankel expansion, and two transitional
  3294. * expansions for large v. If v is not too large, it
  3295. * is reduced by recurrence to a region of best accuracy.
  3296. * The transitional expansions give 12D accuracy for v > 500.
  3297. *
  3298. *
  3299. *
  3300. * ACCURACY:
  3301. * Results for integer v are indicated by *, where x and v
  3302. * both vary from -125 to +125. Otherwise,
  3303. * x ranges from 0 to 125, v ranges as indicated by "domain."
  3304. * Error criterion is absolute, except relative when |jv()| > 1.
  3305. *
  3306. * arithmetic v domain x domain # trials peak rms
  3307. * IEEE 0,125 0,125 100000 4.6e-15 2.2e-16
  3308. * IEEE -125,0 0,125 40000 5.4e-11 3.7e-13
  3309. * IEEE 0,500 0,500 20000 4.4e-15 4.0e-16
  3310. * Integer v:
  3311. * IEEE -125,125 -125,125 50000 3.5e-15* 1.9e-16*
  3312. *
  3313. */
  3314. /* k0.c
  3315. *
  3316. * Modified Bessel function, third kind, order zero
  3317. *
  3318. *
  3319. *
  3320. * SYNOPSIS:
  3321. *
  3322. * double x, y, k0();
  3323. *
  3324. * y = k0( x );
  3325. *
  3326. *
  3327. *
  3328. * DESCRIPTION:
  3329. *
  3330. * Returns modified Bessel function of the third kind
  3331. * of order zero of the argument.
  3332. *
  3333. * The range is partitioned into the two intervals [0,8] and
  3334. * (8, infinity). Chebyshev polynomial expansions are employed
  3335. * in each interval.
  3336. *
  3337. *
  3338. *
  3339. * ACCURACY:
  3340. *
  3341. * Tested at 2000 random points between 0 and 8. Peak absolute
  3342. * error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
  3343. * Relative error:
  3344. * arithmetic domain # trials peak rms
  3345. * DEC 0, 30 3100 1.3e-16 2.1e-17
  3346. * IEEE 0, 30 30000 1.2e-15 1.6e-16
  3347. *
  3348. * ERROR MESSAGES:
  3349. *
  3350. * message condition value returned
  3351. * K0 domain x <= 0 MAXNUM
  3352. *
  3353. */
  3354. /* k0e()
  3355. *
  3356. * Modified Bessel function, third kind, order zero,
  3357. * exponentially scaled
  3358. *
  3359. *
  3360. *
  3361. * SYNOPSIS:
  3362. *
  3363. * double x, y, k0e();
  3364. *
  3365. * y = k0e( x );
  3366. *
  3367. *
  3368. *
  3369. * DESCRIPTION:
  3370. *
  3371. * Returns exponentially scaled modified Bessel function
  3372. * of the third kind of order zero of the argument.
  3373. *
  3374. *
  3375. *
  3376. * ACCURACY:
  3377. *
  3378. * Relative error:
  3379. * arithmetic domain # trials peak rms
  3380. * IEEE 0, 30 30000 1.4e-15 1.4e-16
  3381. * See k0().
  3382. *
  3383. */
  3384. /* k1.c
  3385. *
  3386. * Modified Bessel function, third kind, order one
  3387. *
  3388. *
  3389. *
  3390. * SYNOPSIS:
  3391. *
  3392. * double x, y, k1();
  3393. *
  3394. * y = k1( x );
  3395. *
  3396. *
  3397. *
  3398. * DESCRIPTION:
  3399. *
  3400. * Computes the modified Bessel function of the third kind
  3401. * of order one of the argument.
  3402. *
  3403. * The range is partitioned into the two intervals [0,2] and
  3404. * (2, infinity). Chebyshev polynomial expansions are employed
  3405. * in each interval.
  3406. *
  3407. *
  3408. *
  3409. * ACCURACY:
  3410. *
  3411. * Relative error:
  3412. * arithmetic domain # trials peak rms
  3413. * DEC 0, 30 3300 8.9e-17 2.2e-17
  3414. * IEEE 0, 30 30000 1.2e-15 1.6e-16
  3415. *
  3416. * ERROR MESSAGES:
  3417. *
  3418. * message condition value returned
  3419. * k1 domain x <= 0 MAXNUM
  3420. *
  3421. */
  3422. /* k1e.c
  3423. *
  3424. * Modified Bessel function, third kind, order one,
  3425. * exponentially scaled
  3426. *
  3427. *
  3428. *
  3429. * SYNOPSIS:
  3430. *
  3431. * double x, y, k1e();
  3432. *
  3433. * y = k1e( x );
  3434. *
  3435. *
  3436. *
  3437. * DESCRIPTION:
  3438. *
  3439. * Returns exponentially scaled modified Bessel function
  3440. * of the third kind of order one of the argument:
  3441. *
  3442. * k1e(x) = exp(x) * k1(x).
  3443. *
  3444. *
  3445. *
  3446. * ACCURACY:
  3447. *
  3448. * Relative error:
  3449. * arithmetic domain # trials peak rms
  3450. * IEEE 0, 30 30000 7.8e-16 1.2e-16
  3451. * See k1().
  3452. *
  3453. */
  3454. /* kn.c
  3455. *
  3456. * Modified Bessel function, third kind, integer order
  3457. *
  3458. *
  3459. *
  3460. * SYNOPSIS:
  3461. *
  3462. * double x, y, kn();
  3463. * int n;
  3464. *
  3465. * y = kn( n, x );
  3466. *
  3467. *
  3468. *
  3469. * DESCRIPTION:
  3470. *
  3471. * Returns modified Bessel function of the third kind
  3472. * of order n of the argument.
  3473. *
  3474. * The range is partitioned into the two intervals [0,9.55] and
  3475. * (9.55, infinity). An ascending power series is used in the
  3476. * low range, and an asymptotic expansion in the high range.
  3477. *
  3478. *
  3479. *
  3480. * ACCURACY:
  3481. *
  3482. * Relative error:
  3483. * arithmetic domain # trials peak rms
  3484. * DEC 0,30 3000 1.3e-9 5.8e-11
  3485. * IEEE 0,30 90000 1.8e-8 3.0e-10
  3486. *
  3487. * Error is high only near the crossover point x = 9.55
  3488. * between the two expansions used.
  3489. */
  3490. /* Re Kolmogorov statistics, here is Birnbaum and Tingey's formula for the
  3491. distribution of D+, the maximum of all positive deviations between a
  3492. theoretical distribution function P(x) and an empirical one Sn(x)
  3493. from n samples.
  3494. +
  3495. D = sup [ P(x) - Sn(x) ]
  3496. n -inf < x < inf
  3497. [n(1-e)]
  3498. + - v-1 n-v
  3499. Pr{D > e} = > C e (e + v/n) (1 - e - v/n)
  3500. n - n v
  3501. v=0
  3502. [n(1-e)] is the largest integer not exceeding n(1-e).
  3503. nCv is the number of combinations of n things taken v at a time.
  3504. Exact Smirnov statistic, for one-sided test:
  3505. double
  3506. smirnov (n, e)
  3507. int n;
  3508. double e;
  3509. Kolmogorov's limiting distribution of two-sided test, returns
  3510. probability that sqrt(n) * max deviation > y,
  3511. or that max deviation > y/sqrt(n).
  3512. The approximation is useful for the tail of the distribution
  3513. when n is large.
  3514. double
  3515. kolmogorov (y)
  3516. double y;
  3517. Functional inverse of Smirnov distribution
  3518. finds e such that smirnov(n,e) = p.
  3519. double
  3520. smirnovi (n, p)
  3521. int n;
  3522. double p;
  3523. Functional inverse of Kolmogorov statistic for two-sided test.
  3524. Finds y such that kolmogorov(y) = p.
  3525. If e = smirnovi (n,p), then kolmogi(2 * p) / sqrt(n) should
  3526. be close to e.
  3527. double
  3528. kolmogi (p)
  3529. double p;
  3530. */
  3531. /* Levnsn.c */
  3532. /* Levinson-Durbin LPC
  3533. *
  3534. * | R0 R1 R2 ... RN-1 | | A1 | | -R1 |
  3535. * | R1 R0 R1 ... RN-2 | | A2 | | -R2 |
  3536. * | R2 R1 R0 ... RN-3 | | A3 | = | -R3 |
  3537. * | ... | | ...| | ... |
  3538. * | RN-1 RN-2... R0 | | AN | | -RN |
  3539. *
  3540. * Ref: John Makhoul, "Linear Prediction, A Tutorial Review"
  3541. * Proc. IEEE Vol. 63, PP 561-580 April, 1975.
  3542. *
  3543. * R is the input autocorrelation function. R0 is the zero lag
  3544. * term. A is the output array of predictor coefficients. Note
  3545. * that a filter impulse response has a coefficient of 1.0 preceding
  3546. * A1. E is an array of mean square error for each prediction order
  3547. * 1 to N. REFL is an output array of the reflection coefficients.
  3548. */
  3549. /* log.c
  3550. *
  3551. * Natural logarithm
  3552. *
  3553. *
  3554. *
  3555. * SYNOPSIS:
  3556. *
  3557. * double x, y, log();
  3558. *
  3559. * y = log( x );
  3560. *
  3561. *
  3562. *
  3563. * DESCRIPTION:
  3564. *
  3565. * Returns the base e (2.718...) logarithm of x.
  3566. *
  3567. * The argument is separated into its exponent and fractional
  3568. * parts. If the exponent is between -1 and +1, the logarithm
  3569. * of the fraction is approximated by
  3570. *
  3571. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  3572. *
  3573. * Otherwise, setting z = 2(x-1)/x+1),
  3574. *
  3575. * log(x) = z + z**3 P(z)/Q(z).
  3576. *
  3577. *
  3578. *
  3579. * ACCURACY:
  3580. *
  3581. * Relative error:
  3582. * arithmetic domain # trials peak rms
  3583. * IEEE 0.5, 2.0 150000 1.44e-16 5.06e-17
  3584. * IEEE +-MAXNUM 30000 1.20e-16 4.78e-17
  3585. * DEC 0, 10 170000 1.8e-17 6.3e-18
  3586. *
  3587. * In the tests over the interval [+-MAXNUM], the logarithms
  3588. * of the random arguments were uniformly distributed over
  3589. * [0, MAXLOG].
  3590. *
  3591. * ERROR MESSAGES:
  3592. *
  3593. * log singularity: x = 0; returns -INFINITY
  3594. * log domain: x < 0; returns NAN
  3595. */
  3596. /* log10.c
  3597. *
  3598. * Common logarithm
  3599. *
  3600. *
  3601. *
  3602. * SYNOPSIS:
  3603. *
  3604. * double x, y, log10();
  3605. *
  3606. * y = log10( x );
  3607. *
  3608. *
  3609. *
  3610. * DESCRIPTION:
  3611. *
  3612. * Returns logarithm to the base 10 of x.
  3613. *
  3614. * The argument is separated into its exponent and fractional
  3615. * parts. The logarithm of the fraction is approximated by
  3616. *
  3617. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  3618. *
  3619. *
  3620. *
  3621. * ACCURACY:
  3622. *
  3623. * Relative error:
  3624. * arithmetic domain # trials peak rms
  3625. * IEEE 0.5, 2.0 30000 1.5e-16 5.0e-17
  3626. * IEEE 0, MAXNUM 30000 1.4e-16 4.8e-17
  3627. * DEC 1, MAXNUM 50000 2.5e-17 6.0e-18
  3628. *
  3629. * In the tests over the interval [1, MAXNUM], the logarithms
  3630. * of the random arguments were uniformly distributed over
  3631. * [0, MAXLOG].
  3632. *
  3633. * ERROR MESSAGES:
  3634. *
  3635. * log10 singularity: x = 0; returns -INFINITY
  3636. * log10 domain: x < 0; returns NAN
  3637. */
  3638. /* log2.c
  3639. *
  3640. * Base 2 logarithm
  3641. *
  3642. *
  3643. *
  3644. * SYNOPSIS:
  3645. *
  3646. * double x, y, log2();
  3647. *
  3648. * y = log2( x );
  3649. *
  3650. *
  3651. *
  3652. * DESCRIPTION:
  3653. *
  3654. * Returns the base 2 logarithm of x.
  3655. *
  3656. * The argument is separated into its exponent and fractional
  3657. * parts. If the exponent is between -1 and +1, the base e
  3658. * logarithm of the fraction is approximated by
  3659. *
  3660. * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
  3661. *
  3662. * Otherwise, setting z = 2(x-1)/x+1),
  3663. *
  3664. * log(x) = z + z**3 P(z)/Q(z).
  3665. *
  3666. *
  3667. *
  3668. * ACCURACY:
  3669. *
  3670. * Relative error:
  3671. * arithmetic domain # trials peak rms
  3672. * IEEE 0.5, 2.0 30000 2.0e-16 5.5e-17
  3673. * IEEE exp(+-700) 40000 1.3e-16 4.6e-17
  3674. *
  3675. * In the tests over the interval [exp(+-700)], the logarithms
  3676. * of the random arguments were uniformly distributed.
  3677. *
  3678. * ERROR MESSAGES:
  3679. *
  3680. * log2 singularity: x = 0; returns -INFINITY
  3681. * log2 domain: x < 0; returns NAN
  3682. */
  3683. /* lrand.c
  3684. *
  3685. * Pseudorandom number generator
  3686. *
  3687. *
  3688. *
  3689. * SYNOPSIS:
  3690. *
  3691. * long y, drand();
  3692. *
  3693. * drand( &y );
  3694. *
  3695. *
  3696. *
  3697. * DESCRIPTION:
  3698. *
  3699. * Yields a long integer random number.
  3700. *
  3701. * The three-generator congruential algorithm by Brian
  3702. * Wichmann and David Hill (BYTE magazine, March, 1987,
  3703. * pp 127-8) is used. The period, given by them, is
  3704. * 6953607871644.
  3705. *
  3706. *
  3707. */
  3708. /* lsqrt.c
  3709. *
  3710. * Integer square root
  3711. *
  3712. *
  3713. *
  3714. * SYNOPSIS:
  3715. *
  3716. * long x, y;
  3717. * long lsqrt();
  3718. *
  3719. * y = lsqrt( x );
  3720. *
  3721. *
  3722. *
  3723. * DESCRIPTION:
  3724. *
  3725. * Returns a long integer square root of the long integer
  3726. * argument. The computation is by binary long division.
  3727. *
  3728. * The largest possible result is lsqrt(2,147,483,647)
  3729. * = 46341.
  3730. *
  3731. * If x < 0, the square root of |x| is returned, and an
  3732. * error message is printed.
  3733. *
  3734. *
  3735. * ACCURACY:
  3736. *
  3737. * An extra, roundoff, bit is computed; hence the result
  3738. * is the nearest integer to the actual square root.
  3739. * NOTE: only DEC arithmetic is currently supported.
  3740. *
  3741. */
  3742. /* minv.c
  3743. *
  3744. * Matrix inversion
  3745. *
  3746. *
  3747. *
  3748. * SYNOPSIS:
  3749. *
  3750. * int n, errcod;
  3751. * double A[n*n], X[n*n];
  3752. * double B[n];
  3753. * int IPS[n];
  3754. * int minv();
  3755. *
  3756. * errcod = minv( A, X, n, B, IPS );
  3757. *
  3758. *
  3759. *
  3760. * DESCRIPTION:
  3761. *
  3762. * Finds the inverse of the n by n matrix A. The result goes
  3763. * to X. B and IPS are scratch pad arrays of length n.
  3764. * The contents of matrix A are destroyed.
  3765. *
  3766. * The routine returns nonzero on error; error messages are printed
  3767. * by subroutine simq().
  3768. *
  3769. */
  3770. /* mmmpy.c
  3771. *
  3772. * Matrix multiply
  3773. *
  3774. *
  3775. *
  3776. * SYNOPSIS:
  3777. *
  3778. * int r, c;
  3779. * double A[r*c], B[c*r], Y[r*r];
  3780. *
  3781. * mmmpy( r, c, A, B, Y );
  3782. *
  3783. *
  3784. *
  3785. * DESCRIPTION:
  3786. *
  3787. * Y = A B
  3788. * c-1
  3789. * --
  3790. * Y[i][j] = > A[i][k] B[k][j]
  3791. * --
  3792. * k=0
  3793. *
  3794. * Multiplies an r (rows) by c (columns) matrix A on the left
  3795. * by a c (rows) by r (columns) matrix B on the right
  3796. * to produce an r by r matrix Y.
  3797. *
  3798. *
  3799. */
  3800. /* mtherr.c
  3801. *
  3802. * Library common error handling routine
  3803. *
  3804. *
  3805. *
  3806. * SYNOPSIS:
  3807. *
  3808. * char *fctnam;
  3809. * int code;
  3810. * int mtherr();
  3811. *
  3812. * mtherr( fctnam, code );
  3813. *
  3814. *
  3815. *
  3816. * DESCRIPTION:
  3817. *
  3818. * This routine may be called to report one of the following
  3819. * error conditions (in the include file math.h).
  3820. *
  3821. * Mnemonic Value Significance
  3822. *
  3823. * DOMAIN 1 argument domain error
  3824. * SING 2 function singularity
  3825. * OVERFLOW 3 overflow range error
  3826. * UNDERFLOW 4 underflow range error
  3827. * TLOSS 5 total loss of precision
  3828. * PLOSS 6 partial loss of precision
  3829. * EDOM 33 Unix domain error code
  3830. * ERANGE 34 Unix range error code
  3831. *
  3832. * The default version of the file prints the function name,
  3833. * passed to it by the pointer fctnam, followed by the
  3834. * error condition. The display is directed to the standard
  3835. * output device. The routine then returns to the calling
  3836. * program. Users may wish to modify the program to abort by
  3837. * calling exit() under severe error conditions such as domain
  3838. * errors.
  3839. *
  3840. * Since all error conditions pass control to this function,
  3841. * the display may be easily changed, eliminated, or directed
  3842. * to an error logging device.
  3843. *
  3844. * SEE ALSO:
  3845. *
  3846. * math.h
  3847. *
  3848. */
  3849. /* mtransp.c
  3850. *
  3851. * Matrix transpose
  3852. *
  3853. *
  3854. *
  3855. * SYNOPSIS:
  3856. *
  3857. * int n;
  3858. * double A[n*n], T[n*n];
  3859. *
  3860. * mtransp( n, A, T );
  3861. *
  3862. *
  3863. *
  3864. * DESCRIPTION:
  3865. *
  3866. *
  3867. * T[r][c] = A[c][r]
  3868. *
  3869. *
  3870. * Transposes the n by n square matrix A and puts the result in T.
  3871. * The output, T, may occupy the same storage as A.
  3872. *
  3873. *
  3874. *
  3875. */
  3876. /* mvmpy.c
  3877. *
  3878. * Matrix times vector
  3879. *
  3880. *
  3881. *
  3882. * SYNOPSIS:
  3883. *
  3884. * int r, c;
  3885. * double A[r*c], V[c], Y[r];
  3886. *
  3887. * mvmpy( r, c, A, V, Y );
  3888. *
  3889. *
  3890. *
  3891. * DESCRIPTION:
  3892. *
  3893. * c-1
  3894. * --
  3895. * Y[j] = > A[j][k] V[k] , j = 1, ..., r
  3896. * --
  3897. * k=0
  3898. *
  3899. * Multiplies the r (rows) by c (columns) matrix A on the left
  3900. * by column vector V of dimension c on the right
  3901. * to produce a (column) vector Y output of dimension r.
  3902. *
  3903. *
  3904. *
  3905. *
  3906. */
  3907. /* nbdtr.c
  3908. *
  3909. * Negative binomial distribution
  3910. *
  3911. *
  3912. *
  3913. * SYNOPSIS:
  3914. *
  3915. * int k, n;
  3916. * double p, y, nbdtr();
  3917. *
  3918. * y = nbdtr( k, n, p );
  3919. *
  3920. * DESCRIPTION:
  3921. *
  3922. * Returns the sum of the terms 0 through k of the negative
  3923. * binomial distribution:
  3924. *
  3925. * k
  3926. * -- ( n+j-1 ) n j
  3927. * > ( ) p (1-p)
  3928. * -- ( j )
  3929. * j=0
  3930. *
  3931. * In a sequence of Bernoulli trials, this is the probability
  3932. * that k or fewer failures precede the nth success.
  3933. *
  3934. * The terms are not computed individually; instead the incomplete
  3935. * beta integral is employed, according to the formula
  3936. *
  3937. * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
  3938. *
  3939. * The arguments must be positive, with p ranging from 0 to 1.
  3940. *
  3941. * ACCURACY:
  3942. *
  3943. * Tested at random points (a,b,p), with p between 0 and 1.
  3944. *
  3945. * a,b Relative error:
  3946. * arithmetic domain # trials peak rms
  3947. * IEEE 0,100 100000 1.7e-13 8.8e-15
  3948. * See also incbet.c.
  3949. *
  3950. */
  3951. /* nbdtrc.c
  3952. *
  3953. * Complemented negative binomial distribution
  3954. *
  3955. *
  3956. *
  3957. * SYNOPSIS:
  3958. *
  3959. * int k, n;
  3960. * double p, y, nbdtrc();
  3961. *
  3962. * y = nbdtrc( k, n, p );
  3963. *
  3964. * DESCRIPTION:
  3965. *
  3966. * Returns the sum of the terms k+1 to infinity of the negative
  3967. * binomial distribution:
  3968. *
  3969. * inf
  3970. * -- ( n+j-1 ) n j
  3971. * > ( ) p (1-p)
  3972. * -- ( j )
  3973. * j=k+1
  3974. *
  3975. * The terms are not computed individually; instead the incomplete
  3976. * beta integral is employed, according to the formula
  3977. *
  3978. * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
  3979. *
  3980. * The arguments must be positive, with p ranging from 0 to 1.
  3981. *
  3982. * ACCURACY:
  3983. *
  3984. * Tested at random points (a,b,p), with p between 0 and 1.
  3985. *
  3986. * a,b Relative error:
  3987. * arithmetic domain # trials peak rms
  3988. * IEEE 0,100 100000 1.7e-13 8.8e-15
  3989. * See also incbet.c.
  3990. */
  3991. /* nbdtrc
  3992. *
  3993. * Complemented negative binomial distribution
  3994. *
  3995. *
  3996. *
  3997. * SYNOPSIS:
  3998. *
  3999. * int k, n;
  4000. * double p, y, nbdtrc();
  4001. *
  4002. * y = nbdtrc( k, n, p );
  4003. *
  4004. * DESCRIPTION:
  4005. *
  4006. * Returns the sum of the terms k+1 to infinity of the negative
  4007. * binomial distribution:
  4008. *
  4009. * inf
  4010. * -- ( n+j-1 ) n j
  4011. * > ( ) p (1-p)
  4012. * -- ( j )
  4013. * j=k+1
  4014. *
  4015. * The terms are not computed individually; instead the incomplete
  4016. * beta integral is employed, according to the formula
  4017. *
  4018. * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
  4019. *
  4020. * The arguments must be positive, with p ranging from 0 to 1.
  4021. *
  4022. * ACCURACY:
  4023. *
  4024. * See incbet.c.
  4025. */
  4026. /* nbdtri
  4027. *
  4028. * Functional inverse of negative binomial distribution
  4029. *
  4030. *
  4031. *
  4032. * SYNOPSIS:
  4033. *
  4034. * int k, n;
  4035. * double p, y, nbdtri();
  4036. *
  4037. * p = nbdtri( k, n, y );
  4038. *
  4039. * DESCRIPTION:
  4040. *
  4041. * Finds the argument p such that nbdtr(k,n,p) is equal to y.
  4042. *
  4043. * ACCURACY:
  4044. *
  4045. * Tested at random points (a,b,y), with y between 0 and 1.
  4046. *
  4047. * a,b Relative error:
  4048. * arithmetic domain # trials peak rms
  4049. * IEEE 0,100 100000 1.5e-14 8.5e-16
  4050. * See also incbi.c.
  4051. */
  4052. /* ndtr.c
  4053. *
  4054. * Normal distribution function
  4055. *
  4056. *
  4057. *
  4058. * SYNOPSIS:
  4059. *
  4060. * double x, y, ndtr();
  4061. *
  4062. * y = ndtr( x );
  4063. *
  4064. *
  4065. *
  4066. * DESCRIPTION:
  4067. *
  4068. * Returns the area under the Gaussian probability density
  4069. * function, integrated from minus infinity to x:
  4070. *
  4071. * x
  4072. * -
  4073. * 1 | | 2
  4074. * ndtr(x) = --------- | exp( - t /2 ) dt
  4075. * sqrt(2pi) | |
  4076. * -
  4077. * -inf.
  4078. *
  4079. * = ( 1 + erf(z) ) / 2
  4080. * = erfc(z) / 2
  4081. *
  4082. * where z = x/sqrt(2). Computation is via the functions
  4083. * erf and erfc.
  4084. *
  4085. *
  4086. * ACCURACY:
  4087. *
  4088. * Relative error:
  4089. * arithmetic domain # trials peak rms
  4090. * DEC -13,0 8000 2.1e-15 4.8e-16
  4091. * IEEE -13,0 30000 3.4e-14 6.7e-15
  4092. *
  4093. *
  4094. * ERROR MESSAGES:
  4095. *
  4096. * message condition value returned
  4097. * erfc underflow x > 37.519379347 0.0
  4098. *
  4099. */
  4100. /* erf.c
  4101. *
  4102. * Error function
  4103. *
  4104. *
  4105. *
  4106. * SYNOPSIS:
  4107. *
  4108. * double x, y, erf();
  4109. *
  4110. * y = erf( x );
  4111. *
  4112. *
  4113. *
  4114. * DESCRIPTION:
  4115. *
  4116. * The integral is
  4117. *
  4118. * x
  4119. * -
  4120. * 2 | | 2
  4121. * erf(x) = -------- | exp( - t ) dt.
  4122. * sqrt(pi) | |
  4123. * -
  4124. * 0
  4125. *
  4126. * The magnitude of x is limited to 9.231948545 for DEC
  4127. * arithmetic; 1 or -1 is returned outside this range.
  4128. *
  4129. * For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
  4130. * erf(x) = 1 - erfc(x).
  4131. *
  4132. *
  4133. *
  4134. * ACCURACY:
  4135. *
  4136. * Relative error:
  4137. * arithmetic domain # trials peak rms
  4138. * DEC 0,1 14000 4.7e-17 1.5e-17
  4139. * IEEE 0,1 30000 3.7e-16 1.0e-16
  4140. *
  4141. */
  4142. /* erfc.c
  4143. *
  4144. * Complementary error function
  4145. *
  4146. *
  4147. *
  4148. * SYNOPSIS:
  4149. *
  4150. * double x, y, erfc();
  4151. *
  4152. * y = erfc( x );
  4153. *
  4154. *
  4155. *
  4156. * DESCRIPTION:
  4157. *
  4158. *
  4159. * 1 - erf(x) =
  4160. *
  4161. * inf.
  4162. * -
  4163. * 2 | | 2
  4164. * erfc(x) = -------- | exp( - t ) dt
  4165. * sqrt(pi) | |
  4166. * -
  4167. * x
  4168. *
  4169. *
  4170. * For small x, erfc(x) = 1 - erf(x); otherwise rational
  4171. * approximations are computed.
  4172. *
  4173. *
  4174. *
  4175. * ACCURACY:
  4176. *
  4177. * Relative error:
  4178. * arithmetic domain # trials peak rms
  4179. * DEC 0, 9.2319 12000 5.1e-16 1.2e-16
  4180. * IEEE 0,26.6417 30000 5.7e-14 1.5e-14
  4181. *
  4182. *
  4183. * ERROR MESSAGES:
  4184. *
  4185. * message condition value returned
  4186. * erfc underflow x > 9.231948545 (DEC) 0.0
  4187. *
  4188. *
  4189. */
  4190. /* ndtri.c
  4191. *
  4192. * Inverse of Normal distribution function
  4193. *
  4194. *
  4195. *
  4196. * SYNOPSIS:
  4197. *
  4198. * double x, y, ndtri();
  4199. *
  4200. * x = ndtri( y );
  4201. *
  4202. *
  4203. *
  4204. * DESCRIPTION:
  4205. *
  4206. * Returns the argument, x, for which the area under the
  4207. * Gaussian probability density function (integrated from
  4208. * minus infinity to x) is equal to y.
  4209. *
  4210. *
  4211. * For small arguments 0 < y < exp(-2), the program computes
  4212. * z = sqrt( -2.0 * log(y) ); then the approximation is
  4213. * x = z - log(z)/z - (1/z) P(1/z) / Q(1/z).
  4214. * There are two rational functions P/Q, one for 0 < y < exp(-32)
  4215. * and the other for y up to exp(-2). For larger arguments,
  4216. * w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).
  4217. *
  4218. *
  4219. * ACCURACY:
  4220. *
  4221. * Relative error:
  4222. * arithmetic domain # trials peak rms
  4223. * DEC 0.125, 1 5500 9.5e-17 2.1e-17
  4224. * DEC 6e-39, 0.135 3500 5.7e-17 1.3e-17
  4225. * IEEE 0.125, 1 20000 7.2e-16 1.3e-16
  4226. * IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17
  4227. *
  4228. *
  4229. * ERROR MESSAGES:
  4230. *
  4231. * message condition value returned
  4232. * ndtri domain x <= 0 -MAXNUM
  4233. * ndtri domain x >= 1 MAXNUM
  4234. *
  4235. */
  4236. /* pdtr.c
  4237. *
  4238. * Poisson distribution
  4239. *
  4240. *
  4241. *
  4242. * SYNOPSIS:
  4243. *
  4244. * int k;
  4245. * double m, y, pdtr();
  4246. *
  4247. * y = pdtr( k, m );
  4248. *
  4249. *
  4250. *
  4251. * DESCRIPTION:
  4252. *
  4253. * Returns the sum of the first k terms of the Poisson
  4254. * distribution:
  4255. *
  4256. * k j
  4257. * -- -m m
  4258. * > e --
  4259. * -- j!
  4260. * j=0
  4261. *
  4262. * The terms are not summed directly; instead the incomplete
  4263. * gamma integral is employed, according to the relation
  4264. *
  4265. * y = pdtr( k, m ) = igamc( k+1, m ).
  4266. *
  4267. * The arguments must both be positive.
  4268. *
  4269. *
  4270. *
  4271. * ACCURACY:
  4272. *
  4273. * See igamc().
  4274. *
  4275. */
  4276. /* pdtrc()
  4277. *
  4278. * Complemented poisson distribution
  4279. *
  4280. *
  4281. *
  4282. * SYNOPSIS:
  4283. *
  4284. * int k;
  4285. * double m, y, pdtrc();
  4286. *
  4287. * y = pdtrc( k, m );
  4288. *
  4289. *
  4290. *
  4291. * DESCRIPTION:
  4292. *
  4293. * Returns the sum of the terms k+1 to infinity of the Poisson
  4294. * distribution:
  4295. *
  4296. * inf. j
  4297. * -- -m m
  4298. * > e --
  4299. * -- j!
  4300. * j=k+1
  4301. *
  4302. * The terms are not summed directly; instead the incomplete
  4303. * gamma integral is employed, according to the formula
  4304. *
  4305. * y = pdtrc( k, m ) = igam( k+1, m ).
  4306. *
  4307. * The arguments must both be positive.
  4308. *
  4309. *
  4310. *
  4311. * ACCURACY:
  4312. *
  4313. * See igam.c.
  4314. *
  4315. */
  4316. /* pdtri()
  4317. *
  4318. * Inverse Poisson distribution
  4319. *
  4320. *
  4321. *
  4322. * SYNOPSIS:
  4323. *
  4324. * int k;
  4325. * double m, y, pdtr();
  4326. *
  4327. * m = pdtri( k, y );
  4328. *
  4329. *
  4330. *
  4331. *
  4332. * DESCRIPTION:
  4333. *
  4334. * Finds the Poisson variable x such that the integral
  4335. * from 0 to x of the Poisson density is equal to the
  4336. * given probability y.
  4337. *
  4338. * This is accomplished using the inverse gamma integral
  4339. * function and the relation
  4340. *
  4341. * m = igami( k+1, y ).
  4342. *
  4343. *
  4344. *
  4345. *
  4346. * ACCURACY:
  4347. *
  4348. * See igami.c.
  4349. *
  4350. * ERROR MESSAGES:
  4351. *
  4352. * message condition value returned
  4353. * pdtri domain y < 0 or y >= 1 0.0
  4354. * k < 0
  4355. *
  4356. */
  4357. /* polevl.c
  4358. * p1evl.c
  4359. *
  4360. * Evaluate polynomial
  4361. *
  4362. *
  4363. *
  4364. * SYNOPSIS:
  4365. *
  4366. * int N;
  4367. * double x, y, coef[N+1], polevl[];
  4368. *
  4369. * y = polevl( x, coef, N );
  4370. *
  4371. *
  4372. *
  4373. * DESCRIPTION:
  4374. *
  4375. * Evaluates polynomial of degree N:
  4376. *
  4377. * 2 N
  4378. * y = C + C x + C x +...+ C x
  4379. * 0 1 2 N
  4380. *
  4381. * Coefficients are stored in reverse order:
  4382. *
  4383. * coef[0] = C , ..., coef[N] = C .
  4384. * N 0
  4385. *
  4386. * The function p1evl() assumes that coef[N] = 1.0 and is
  4387. * omitted from the array. Its calling arguments are
  4388. * otherwise the same as polevl().
  4389. *
  4390. *
  4391. * SPEED:
  4392. *
  4393. * In the interest of speed, there are no checks for out
  4394. * of bounds arithmetic. This routine is used by most of
  4395. * the functions in the library. Depending on available
  4396. * equipment features, the user may wish to rewrite the
  4397. * program in microcode or assembly language.
  4398. *
  4399. */
  4400. /* polmisc.c
  4401. * Square root, sine, cosine, and arctangent of polynomial.
  4402. * See polyn.c for data structures and discussion.
  4403. */
  4404. /* polrt.c
  4405. *
  4406. * Find roots of a polynomial
  4407. *
  4408. *
  4409. *
  4410. * SYNOPSIS:
  4411. *
  4412. * typedef struct
  4413. * {
  4414. * double r;
  4415. * double i;
  4416. * }cmplx;
  4417. *
  4418. * double xcof[], cof[];
  4419. * int m;
  4420. * cmplx root[];
  4421. *
  4422. * polrt( xcof, cof, m, root )
  4423. *
  4424. *
  4425. *
  4426. * DESCRIPTION:
  4427. *
  4428. * Iterative determination of the roots of a polynomial of
  4429. * degree m whose coefficient vector is xcof[]. The
  4430. * coefficients are arranged in ascending order; i.e., the
  4431. * coefficient of x**m is xcof[m].
  4432. *
  4433. * The array cof[] is working storage the same size as xcof[].
  4434. * root[] is the output array containing the complex roots.
  4435. *
  4436. *
  4437. * ACCURACY:
  4438. *
  4439. * Termination depends on evaluation of the polynomial at
  4440. * the trial values of the roots. The values of multiple roots
  4441. * or of roots that are nearly equal may have poor relative
  4442. * accuracy after the first root in the neighborhood has been
  4443. * found.
  4444. *
  4445. */
  4446. /* polyn.c
  4447. * polyr.c
  4448. * Arithmetic operations on polynomials
  4449. *
  4450. * In the following descriptions a, b, c are polynomials of degree
  4451. * na, nb, nc respectively. The degree of a polynomial cannot
  4452. * exceed a run-time value MAXPOL. An operation that attempts
  4453. * to use or generate a polynomial of higher degree may produce a
  4454. * result that suffers truncation at degree MAXPOL. The value of
  4455. * MAXPOL is set by calling the function
  4456. *
  4457. * polini( maxpol );
  4458. *
  4459. * where maxpol is the desired maximum degree. This must be
  4460. * done prior to calling any of the other functions in this module.
  4461. * Memory for internal temporary polynomial storage is allocated
  4462. * by polini().
  4463. *
  4464. * Each polynomial is represented by an array containing its
  4465. * coefficients, together with a separately declared integer equal
  4466. * to the degree of the polynomial. The coefficients appear in
  4467. * ascending order; that is,
  4468. *
  4469. * 2 na
  4470. * a(x) = a[0] + a[1] * x + a[2] * x + ... + a[na] * x .
  4471. *
  4472. *
  4473. *
  4474. * sum = poleva( a, na, x ); Evaluate polynomial a(t) at t = x.
  4475. * polprt( a, na, D ); Print the coefficients of a to D digits.
  4476. * polclr( a, na ); Set a identically equal to zero, up to a[na].
  4477. * polmov( a, na, b ); Set b = a.
  4478. * poladd( a, na, b, nb, c ); c = b + a, nc = max(na,nb)
  4479. * polsub( a, na, b, nb, c ); c = b - a, nc = max(na,nb)
  4480. * polmul( a, na, b, nb, c ); c = b * a, nc = na+nb
  4481. *
  4482. *
  4483. * Division:
  4484. *
  4485. * i = poldiv( a, na, b, nb, c ); c = b / a, nc = MAXPOL
  4486. *
  4487. * returns i = the degree of the first nonzero coefficient of a.
  4488. * The computed quotient c must be divided by x^i. An error message
  4489. * is printed if a is identically zero.
  4490. *
  4491. *
  4492. * Change of variables:
  4493. * If a and b are polynomials, and t = a(x), then
  4494. * c(t) = b(a(x))
  4495. * is a polynomial found by substituting a(x) for t. The
  4496. * subroutine call for this is
  4497. *
  4498. * polsbt( a, na, b, nb, c );
  4499. *
  4500. *
  4501. * Notes:
  4502. * poldiv() is an integer routine; poleva() is double.
  4503. * Any of the arguments a, b, c may refer to the same array.
  4504. *
  4505. */
  4506. /* pow.c
  4507. *
  4508. * Power function
  4509. *
  4510. *
  4511. *
  4512. * SYNOPSIS:
  4513. *
  4514. * double x, y, z, pow();
  4515. *
  4516. * z = pow( x, y );
  4517. *
  4518. *
  4519. *
  4520. * DESCRIPTION:
  4521. *
  4522. * Computes x raised to the yth power. Analytically,
  4523. *
  4524. * x**y = exp( y log(x) ).
  4525. *
  4526. * Following Cody and Waite, this program uses a lookup table
  4527. * of 2**-i/16 and pseudo extended precision arithmetic to
  4528. * obtain an extra three bits of accuracy in both the logarithm
  4529. * and the exponential.
  4530. *
  4531. *
  4532. *
  4533. * ACCURACY:
  4534. *
  4535. * Relative error:
  4536. * arithmetic domain # trials peak rms
  4537. * IEEE -26,26 30000 4.2e-16 7.7e-17
  4538. * DEC -26,26 60000 4.8e-17 9.1e-18
  4539. * 1/26 < x < 26, with log(x) uniformly distributed.
  4540. * -26 < y < 26, y uniformly distributed.
  4541. * IEEE 0,8700 30000 1.5e-14 2.1e-15
  4542. * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed.
  4543. *
  4544. *
  4545. * ERROR MESSAGES:
  4546. *
  4547. * message condition value returned
  4548. * pow overflow x**y > MAXNUM INFINITY
  4549. * pow underflow x**y < 1/MAXNUM 0.0
  4550. * pow domain x<0 and y noninteger 0.0
  4551. *
  4552. */
  4553. /* powi.c
  4554. *
  4555. * Real raised to integer power
  4556. *
  4557. *
  4558. *
  4559. * SYNOPSIS:
  4560. *
  4561. * double x, y, powi();
  4562. * int n;
  4563. *
  4564. * y = powi( x, n );
  4565. *
  4566. *
  4567. *
  4568. * DESCRIPTION:
  4569. *
  4570. * Returns argument x raised to the nth power.
  4571. * The routine efficiently decomposes n as a sum of powers of
  4572. * two. The desired power is a product of two-to-the-kth
  4573. * powers of x. Thus to compute the 32767 power of x requires
  4574. * 28 multiplications instead of 32767 multiplications.
  4575. *
  4576. *
  4577. *
  4578. * ACCURACY:
  4579. *
  4580. *
  4581. * Relative error:
  4582. * arithmetic x domain n domain # trials peak rms
  4583. * DEC .04,26 -26,26 100000 2.7e-16 4.3e-17
  4584. * IEEE .04,26 -26,26 50000 2.0e-15 3.8e-16
  4585. * IEEE 1,2 -1022,1023 50000 8.6e-14 1.6e-14
  4586. *
  4587. * Returns MAXNUM on overflow, zero on underflow.
  4588. *
  4589. */
  4590. /* psi.c
  4591. *
  4592. * Psi (digamma) function
  4593. *
  4594. *
  4595. * SYNOPSIS:
  4596. *
  4597. * double x, y, psi();
  4598. *
  4599. * y = psi( x );
  4600. *
  4601. *
  4602. * DESCRIPTION:
  4603. *
  4604. * d -
  4605. * psi(x) = -- ln | (x)
  4606. * dx
  4607. *
  4608. * is the logarithmic derivative of the gamma function.
  4609. * For integer x,
  4610. * n-1
  4611. * -
  4612. * psi(n) = -EUL + > 1/k.
  4613. * -
  4614. * k=1
  4615. *
  4616. * This formula is used for 0 < n <= 10. If x is negative, it
  4617. * is transformed to a positive argument by the reflection
  4618. * formula psi(1-x) = psi(x) + pi cot(pi x).
  4619. * For general positive x, the argument is made greater than 10
  4620. * using the recurrence psi(x+1) = psi(x) + 1/x.
  4621. * Then the following asymptotic expansion is applied:
  4622. *
  4623. * inf. B
  4624. * - 2k
  4625. * psi(x) = log(x) - 1/2x - > -------
  4626. * - 2k
  4627. * k=1 2k x
  4628. *
  4629. * where the B2k are Bernoulli numbers.
  4630. *
  4631. * ACCURACY:
  4632. * Relative error (except absolute when |psi| < 1):
  4633. * arithmetic domain # trials peak rms
  4634. * DEC 0,30 2500 1.7e-16 2.0e-17
  4635. * IEEE 0,30 30000 1.3e-15 1.4e-16
  4636. * IEEE -30,0 40000 1.5e-15 2.2e-16
  4637. *
  4638. * ERROR MESSAGES:
  4639. * message condition value returned
  4640. * psi singularity x integer <=0 MAXNUM
  4641. */
  4642. /* revers.c
  4643. *
  4644. * Reversion of power series
  4645. *
  4646. *
  4647. *
  4648. * SYNOPSIS:
  4649. *
  4650. * extern int MAXPOL;
  4651. * int n;
  4652. * double x[n+1], y[n+1];
  4653. *
  4654. * polini(n);
  4655. * revers( y, x, n );
  4656. *
  4657. * Note, polini() initializes the polynomial arithmetic subroutines;
  4658. * see polyn.c.
  4659. *
  4660. *
  4661. * DESCRIPTION:
  4662. *
  4663. * If
  4664. *
  4665. * inf
  4666. * - i
  4667. * y(x) = > a x
  4668. * - i
  4669. * i=1
  4670. *
  4671. * then
  4672. *
  4673. * inf
  4674. * - j
  4675. * x(y) = > A y ,
  4676. * - j
  4677. * j=1
  4678. *
  4679. * where
  4680. * 1
  4681. * A = ---
  4682. * 1 a
  4683. * 1
  4684. *
  4685. * etc. The coefficients of x(y) are found by expanding
  4686. *
  4687. * inf inf
  4688. * - - i
  4689. * x(y) = > A > a x
  4690. * - j - i
  4691. * j=1 i=1
  4692. *
  4693. * and setting each coefficient of x , higher than the first,
  4694. * to zero.
  4695. *
  4696. *
  4697. *
  4698. * RESTRICTIONS:
  4699. *
  4700. * y[0] must be zero, and y[1] must be nonzero.
  4701. *
  4702. */
  4703. /* rgamma.c
  4704. *
  4705. * Reciprocal gamma function
  4706. *
  4707. *
  4708. *
  4709. * SYNOPSIS:
  4710. *
  4711. * double x, y, rgamma();
  4712. *
  4713. * y = rgamma( x );
  4714. *
  4715. *
  4716. *
  4717. * DESCRIPTION:
  4718. *
  4719. * Returns one divided by the gamma function of the argument.
  4720. *
  4721. * The function is approximated by a Chebyshev expansion in
  4722. * the interval [0,1]. Range reduction is by recurrence
  4723. * for arguments between -34.034 and +34.84425627277176174.
  4724. * 1/MAXNUM is returned for positive arguments outside this
  4725. * range. For arguments less than -34.034 the cosecant
  4726. * reflection formula is applied; lograrithms are employed
  4727. * to avoid unnecessary overflow.
  4728. *
  4729. * The reciprocal gamma function has no singularities,
  4730. * but overflow and underflow may occur for large arguments.
  4731. * These conditions return either MAXNUM or 1/MAXNUM with
  4732. * appropriate sign.
  4733. *
  4734. * ACCURACY:
  4735. *
  4736. * Relative error:
  4737. * arithmetic domain # trials peak rms
  4738. * DEC -30,+30 4000 1.2e-16 1.8e-17
  4739. * IEEE -30,+30 30000 1.1e-15 2.0e-16
  4740. * For arguments less than -34.034 the peak error is on the
  4741. * order of 5e-15 (DEC), excepting overflow or underflow.
  4742. */
  4743. /* round.c
  4744. *
  4745. * Round double to nearest or even integer valued double
  4746. *
  4747. *
  4748. *
  4749. * SYNOPSIS:
  4750. *
  4751. * double x, y, round();
  4752. *
  4753. * y = round(x);
  4754. *
  4755. *
  4756. *
  4757. * DESCRIPTION:
  4758. *
  4759. * Returns the nearest integer to x as a double precision
  4760. * floating point result. If x ends in 0.5 exactly, the
  4761. * nearest even integer is chosen.
  4762. *
  4763. *
  4764. *
  4765. * ACCURACY:
  4766. *
  4767. * If x is greater than 1/(2*MACHEP), its closest machine
  4768. * representation is already an integer, so rounding does
  4769. * not change it.
  4770. */
  4771. /* shichi.c
  4772. *
  4773. * Hyperbolic sine and cosine integrals
  4774. *
  4775. *
  4776. *
  4777. * SYNOPSIS:
  4778. *
  4779. * double x, Chi, Shi, shichi();
  4780. *
  4781. * shichi( x, &Chi, &Shi );
  4782. *
  4783. *
  4784. * DESCRIPTION:
  4785. *
  4786. * Approximates the integrals
  4787. *
  4788. * x
  4789. * -
  4790. * | | cosh t - 1
  4791. * Chi(x) = eul + ln x + | ----------- dt,
  4792. * | | t
  4793. * -
  4794. * 0
  4795. *
  4796. * x
  4797. * -
  4798. * | | sinh t
  4799. * Shi(x) = | ------ dt
  4800. * | | t
  4801. * -
  4802. * 0
  4803. *
  4804. * where eul = 0.57721566490153286061 is Euler's constant.
  4805. * The integrals are evaluated by power series for x < 8
  4806. * and by Chebyshev expansions for x between 8 and 88.
  4807. * For large x, both functions approach exp(x)/2x.
  4808. * Arguments greater than 88 in magnitude return MAXNUM.
  4809. *
  4810. *
  4811. * ACCURACY:
  4812. *
  4813. * Test interval 0 to 88.
  4814. * Relative error:
  4815. * arithmetic function # trials peak rms
  4816. * DEC Shi 3000 9.1e-17
  4817. * IEEE Shi 30000 6.9e-16 1.6e-16
  4818. * Absolute error, except relative when |Chi| > 1:
  4819. * DEC Chi 2500 9.3e-17
  4820. * IEEE Chi 30000 8.4e-16 1.4e-16
  4821. */
  4822. /* sici.c
  4823. *
  4824. * Sine and cosine integrals
  4825. *
  4826. *
  4827. *
  4828. * SYNOPSIS:
  4829. *
  4830. * double x, Ci, Si, sici();
  4831. *
  4832. * sici( x, &Si, &Ci );
  4833. *
  4834. *
  4835. * DESCRIPTION:
  4836. *
  4837. * Evaluates the integrals
  4838. *
  4839. * x
  4840. * -
  4841. * | cos t - 1
  4842. * Ci(x) = eul + ln x + | --------- dt,
  4843. * | t
  4844. * -
  4845. * 0
  4846. * x
  4847. * -
  4848. * | sin t
  4849. * Si(x) = | ----- dt
  4850. * | t
  4851. * -
  4852. * 0
  4853. *
  4854. * where eul = 0.57721566490153286061 is Euler's constant.
  4855. * The integrals are approximated by rational functions.
  4856. * For x > 8 auxiliary functions f(x) and g(x) are employed
  4857. * such that
  4858. *
  4859. * Ci(x) = f(x) sin(x) - g(x) cos(x)
  4860. * Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
  4861. *
  4862. *
  4863. * ACCURACY:
  4864. * Test interval = [0,50].
  4865. * Absolute error, except relative when > 1:
  4866. * arithmetic function # trials peak rms
  4867. * IEEE Si 30000 4.4e-16 7.3e-17
  4868. * IEEE Ci 30000 6.9e-16 5.1e-17
  4869. * DEC Si 5000 4.4e-17 9.0e-18
  4870. * DEC Ci 5300 7.9e-17 5.2e-18
  4871. */
  4872. /* simpsn.c */
  4873. * Numerical integration of function tabulated
  4874. * at equally spaced arguments
  4875. */
  4876. /* simq.c
  4877. *
  4878. * Solution of simultaneous linear equations AX = B
  4879. * by Gaussian elimination with partial pivoting
  4880. *
  4881. *
  4882. *
  4883. * SYNOPSIS:
  4884. *
  4885. * double A[n*n], B[n], X[n];
  4886. * int n, flag;
  4887. * int IPS[];
  4888. * int simq();
  4889. *
  4890. * ercode = simq( A, B, X, n, flag, IPS );
  4891. *
  4892. *
  4893. *
  4894. * DESCRIPTION:
  4895. *
  4896. * B, X, IPS are vectors of length n.
  4897. * A is an n x n matrix (i.e., a vector of length n*n),
  4898. * stored row-wise: that is, A(i,j) = A[ij],
  4899. * where ij = i*n + j, which is the transpose of the normal
  4900. * column-wise storage.
  4901. *
  4902. * The contents of matrix A are destroyed.
  4903. *
  4904. * Set flag=0 to solve.
  4905. * Set flag=-1 to do a new back substitution for different B vector
  4906. * using the same A matrix previously reduced when flag=0.
  4907. *
  4908. * The routine returns nonzero on error; messages are printed.
  4909. *
  4910. *
  4911. * ACCURACY:
  4912. *
  4913. * Depends on the conditioning (range of eigenvalues) of matrix A.
  4914. *
  4915. *
  4916. * REFERENCE:
  4917. *
  4918. * Computer Solution of Linear Algebraic Systems,
  4919. * by George E. Forsythe and Cleve B. Moler; Prentice-Hall, 1967.
  4920. *
  4921. */
  4922. /* sin.c
  4923. *
  4924. * Circular sine
  4925. *
  4926. *
  4927. *
  4928. * SYNOPSIS:
  4929. *
  4930. * double x, y, sin();
  4931. *
  4932. * y = sin( x );
  4933. *
  4934. *
  4935. *
  4936. * DESCRIPTION:
  4937. *
  4938. * Range reduction is into intervals of pi/4. The reduction
  4939. * error is nearly eliminated by contriving an extended precision
  4940. * modular arithmetic.
  4941. *
  4942. * Two polynomial approximating functions are employed.
  4943. * Between 0 and pi/4 the sine is approximated by
  4944. * x + x**3 P(x**2).
  4945. * Between pi/4 and pi/2 the cosine is represented as
  4946. * 1 - x**2 Q(x**2).
  4947. *
  4948. *
  4949. * ACCURACY:
  4950. *
  4951. * Relative error:
  4952. * arithmetic domain # trials peak rms
  4953. * DEC 0, 10 150000 3.0e-17 7.8e-18
  4954. * IEEE -1.07e9,+1.07e9 130000 2.1e-16 5.4e-17
  4955. *
  4956. * ERROR MESSAGES:
  4957. *
  4958. * message condition value returned
  4959. * sin total loss x > 1.073741824e9 0.0
  4960. *
  4961. * Partial loss of accuracy begins to occur at x = 2**30
  4962. * = 1.074e9. The loss is not gradual, but jumps suddenly to
  4963. * about 1 part in 10e7. Results may be meaningless for
  4964. * x > 2**49 = 5.6e14. The routine as implemented flags a
  4965. * TLOSS error for x > 2**30 and returns 0.0.
  4966. */
  4967. /* cos.c
  4968. *
  4969. * Circular cosine
  4970. *
  4971. *
  4972. *
  4973. * SYNOPSIS:
  4974. *
  4975. * double x, y, cos();
  4976. *
  4977. * y = cos( x );
  4978. *
  4979. *
  4980. *
  4981. * DESCRIPTION:
  4982. *
  4983. * Range reduction is into intervals of pi/4. The reduction
  4984. * error is nearly eliminated by contriving an extended precision
  4985. * modular arithmetic.
  4986. *
  4987. * Two polynomial approximating functions are employed.
  4988. * Between 0 and pi/4 the cosine is approximated by
  4989. * 1 - x**2 Q(x**2).
  4990. * Between pi/4 and pi/2 the sine is represented as
  4991. * x + x**3 P(x**2).
  4992. *
  4993. *
  4994. * ACCURACY:
  4995. *
  4996. * Relative error:
  4997. * arithmetic domain # trials peak rms
  4998. * IEEE -1.07e9,+1.07e9 130000 2.1e-16 5.4e-17
  4999. * DEC 0,+1.07e9 17000 3.0e-17 7.2e-18
  5000. */
  5001. /* sincos.c
  5002. *
  5003. * Circular sine and cosine of argument in degrees
  5004. * Table lookup and interpolation algorithm
  5005. *
  5006. *
  5007. *
  5008. * SYNOPSIS:
  5009. *
  5010. * double x, sine, cosine, flg, sincos();
  5011. *
  5012. * sincos( x, &sine, &cosine, flg );
  5013. *
  5014. *
  5015. *
  5016. * DESCRIPTION:
  5017. *
  5018. * Returns both the sine and the cosine of the argument x.
  5019. * Several different compile time options and minimax
  5020. * approximations are supplied to permit tailoring the
  5021. * tradeoff between computation speed and accuracy.
  5022. *
  5023. * Since range reduction is time consuming, the reduction
  5024. * of x modulo 360 degrees is also made optional.
  5025. *
  5026. * sin(i) is internally tabulated for 0 <= i <= 90 degrees.
  5027. * Approximation polynomials, ranging from linear interpolation
  5028. * to cubics in (x-i)**2, compute the sine and cosine
  5029. * of the residual x-i which is between -0.5 and +0.5 degree.
  5030. * In the case of the high accuracy options, the residual
  5031. * and the tabulated values are combined using the trigonometry
  5032. * formulas for sin(A+B) and cos(A+B).
  5033. *
  5034. * Compile time options are supplied for 5, 11, or 17 decimal
  5035. * relative accuracy (ACC5, ACC11, ACC17 respectively).
  5036. * A subroutine flag argument "flg" chooses betwen this
  5037. * accuracy and table lookup only (peak absolute error
  5038. * = 0.0087).
  5039. *
  5040. * If the argument flg = 1, then the tabulated value is
  5041. * returned for the nearest whole number of degrees. The
  5042. * approximation polynomials are not computed. At
  5043. * x = 0.5 deg, the absolute error is then sin(0.5) = 0.0087.
  5044. *
  5045. * An intermediate speed and precision can be obtained using
  5046. * the compile time option LINTERP and flg = 1. This yields
  5047. * a linear interpolation using a slope estimated from the sine
  5048. * or cosine at the nearest integer argument. The peak absolute
  5049. * error with this option is 3.8e-5. Relative error at small
  5050. * angles is about 1e-5.
  5051. *
  5052. * If flg = 0, then the approximation polynomials are computed
  5053. * and applied.
  5054. *
  5055. *
  5056. *
  5057. * SPEED:
  5058. *
  5059. * Relative speed comparisons follow for 6MHz IBM AT clone
  5060. * and Microsoft C version 4.0. These figures include
  5061. * software overhead of do loop and function calls.
  5062. * Since system hardware and software vary widely, the
  5063. * numbers should be taken as representative only.
  5064. *
  5065. * flg=0 flg=0 flg=1 flg=1
  5066. * ACC11 ACC5 LINTERP Lookup only
  5067. * In-line 8087 (/FPi)
  5068. * sin(), cos() 1.0 1.0 1.0 1.0
  5069. *
  5070. * In-line 8087 (/FPi)
  5071. * sincos() 1.1 1.4 1.9 3.0
  5072. *
  5073. * Software (/FPa)
  5074. * sin(), cos() 0.19 0.19 0.19 0.19
  5075. *
  5076. * Software (/FPa)
  5077. * sincos() 0.39 0.50 0.73 1.7
  5078. *
  5079. *
  5080. *
  5081. * ACCURACY:
  5082. *
  5083. * The accurate approximations are designed with a relative error
  5084. * criterion. The absolute error is greatest at x = 0.5 degree.
  5085. * It decreases from a local maximum at i+0.5 degrees to full
  5086. * machine precision at each integer i degrees. With the
  5087. * ACC5 option, the relative error of 6.3e-6 is equivalent to
  5088. * an absolute angular error of 0.01 arc second in the argument
  5089. * at x = i+0.5 degrees. For small angles < 0.5 deg, the ACC5
  5090. * accuracy is 6.3e-6 (.00063%) of reading; i.e., the absolute
  5091. * error decreases in proportion to the argument. This is true
  5092. * for both the sine and cosine approximations, since the latter
  5093. * is for the function 1 - cos(x).
  5094. *
  5095. * If absolute error is of most concern, use the compile time
  5096. * option ABSERR to obtain an absolute error of 2.7e-8 for ACC5
  5097. * precision. This is about half the absolute error of the
  5098. * relative precision option. In this case the relative error
  5099. * for small angles will increase to 9.5e-6 -- a reasonable
  5100. * tradeoff.
  5101. */
  5102. /* sindg.c
  5103. *
  5104. * Circular sine of angle in degrees
  5105. *
  5106. *
  5107. *
  5108. * SYNOPSIS:
  5109. *
  5110. * double x, y, sindg();
  5111. *
  5112. * y = sindg( x );
  5113. *
  5114. *
  5115. *
  5116. * DESCRIPTION:
  5117. *
  5118. * Range reduction is into intervals of 45 degrees.
  5119. *
  5120. * Two polynomial approximating functions are employed.
  5121. * Between 0 and pi/4 the sine is approximated by
  5122. * x + x**3 P(x**2).
  5123. * Between pi/4 and pi/2 the cosine is represented as
  5124. * 1 - x**2 P(x**2).
  5125. *
  5126. *
  5127. *
  5128. * ACCURACY:
  5129. *
  5130. * Relative error:
  5131. * arithmetic domain # trials peak rms
  5132. * DEC +-1000 3100 3.3e-17 9.0e-18
  5133. * IEEE +-1000 30000 2.3e-16 5.6e-17
  5134. *
  5135. * ERROR MESSAGES:
  5136. *
  5137. * message condition value returned
  5138. * sindg total loss x > 8.0e14 (DEC) 0.0
  5139. * x > 1.0e14 (IEEE)
  5140. *
  5141. */
  5142. /* cosdg.c
  5143. *
  5144. * Circular cosine of angle in degrees
  5145. *
  5146. *
  5147. *
  5148. * SYNOPSIS:
  5149. *
  5150. * double x, y, cosdg();
  5151. *
  5152. * y = cosdg( x );
  5153. *
  5154. *
  5155. *
  5156. * DESCRIPTION:
  5157. *
  5158. * Range reduction is into intervals of 45 degrees.
  5159. *
  5160. * Two polynomial approximating functions are employed.
  5161. * Between 0 and pi/4 the cosine is approximated by
  5162. * 1 - x**2 P(x**2).
  5163. * Between pi/4 and pi/2 the sine is represented as
  5164. * x + x**3 P(x**2).
  5165. *
  5166. *
  5167. * ACCURACY:
  5168. *
  5169. * Relative error:
  5170. * arithmetic domain # trials peak rms
  5171. * DEC +-1000 3400 3.5e-17 9.1e-18
  5172. * IEEE +-1000 30000 2.1e-16 5.7e-17
  5173. * See also sin().
  5174. *
  5175. */
  5176. /* sinh.c
  5177. *
  5178. * Hyperbolic sine
  5179. *
  5180. *
  5181. *
  5182. * SYNOPSIS:
  5183. *
  5184. * double x, y, sinh();
  5185. *
  5186. * y = sinh( x );
  5187. *
  5188. *
  5189. *
  5190. * DESCRIPTION:
  5191. *
  5192. * Returns hyperbolic sine of argument in the range MINLOG to
  5193. * MAXLOG.
  5194. *
  5195. * The range is partitioned into two segments. If |x| <= 1, a
  5196. * rational function of the form x + x**3 P(x)/Q(x) is employed.
  5197. * Otherwise the calculation is sinh(x) = ( exp(x) - exp(-x) )/2.
  5198. *
  5199. *
  5200. *
  5201. * ACCURACY:
  5202. *
  5203. * Relative error:
  5204. * arithmetic domain # trials peak rms
  5205. * DEC +- 88 50000 4.0e-17 7.7e-18
  5206. * IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
  5207. *
  5208. */
  5209. /* spence.c
  5210. *
  5211. * Dilogarithm
  5212. *
  5213. *
  5214. *
  5215. * SYNOPSIS:
  5216. *
  5217. * double x, y, spence();
  5218. *
  5219. * y = spence( x );
  5220. *
  5221. *
  5222. *
  5223. * DESCRIPTION:
  5224. *
  5225. * Computes the integral
  5226. *
  5227. * x
  5228. * -
  5229. * | | log t
  5230. * spence(x) = - | ----- dt
  5231. * | | t - 1
  5232. * -
  5233. * 1
  5234. *
  5235. * for x >= 0. A rational approximation gives the integral in
  5236. * the interval (0.5, 1.5). Transformation formulas for 1/x
  5237. * and 1-x are employed outside the basic expansion range.
  5238. *
  5239. *
  5240. *
  5241. * ACCURACY:
  5242. *
  5243. * Relative error:
  5244. * arithmetic domain # trials peak rms
  5245. * IEEE 0,4 30000 3.9e-15 5.4e-16
  5246. * DEC 0,4 3000 2.5e-16 4.5e-17
  5247. *
  5248. *
  5249. */
  5250. /* sqrt.c
  5251. *
  5252. * Square root
  5253. *
  5254. *
  5255. *
  5256. * SYNOPSIS:
  5257. *
  5258. * double x, y, sqrt();
  5259. *
  5260. * y = sqrt( x );
  5261. *
  5262. *
  5263. *
  5264. * DESCRIPTION:
  5265. *
  5266. * Returns the square root of x.
  5267. *
  5268. * Range reduction involves isolating the power of two of the
  5269. * argument and using a polynomial approximation to obtain
  5270. * a rough value for the square root. Then Heron's iteration
  5271. * is used three times to converge to an accurate value.
  5272. *
  5273. *
  5274. *
  5275. * ACCURACY:
  5276. *
  5277. *
  5278. * Relative error:
  5279. * arithmetic domain # trials peak rms
  5280. * DEC 0, 10 60000 2.1e-17 7.9e-18
  5281. * IEEE 0,1.7e308 30000 1.7e-16 6.3e-17
  5282. *
  5283. *
  5284. * ERROR MESSAGES:
  5285. *
  5286. * message condition value returned
  5287. * sqrt domain x < 0 0.0
  5288. *
  5289. */
  5290. /* stdtr.c
  5291. *
  5292. * Student's t distribution
  5293. *
  5294. *
  5295. *
  5296. * SYNOPSIS:
  5297. *
  5298. * double t, stdtr();
  5299. * short k;
  5300. *
  5301. * y = stdtr( k, t );
  5302. *
  5303. *
  5304. * DESCRIPTION:
  5305. *
  5306. * Computes the integral from minus infinity to t of the Student
  5307. * t distribution with integer k > 0 degrees of freedom:
  5308. *
  5309. * t
  5310. * -
  5311. * | |
  5312. * - | 2 -(k+1)/2
  5313. * | ( (k+1)/2 ) | ( x )
  5314. * ---------------------- | ( 1 + --- ) dx
  5315. * - | ( k )
  5316. * sqrt( k pi ) | ( k/2 ) |
  5317. * | |
  5318. * -
  5319. * -inf.
  5320. *
  5321. * Relation to incomplete beta integral:
  5322. *
  5323. * 1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )
  5324. * where
  5325. * z = k/(k + t**2).
  5326. *
  5327. * For t < -2, this is the method of computation. For higher t,
  5328. * a direct method is derived from integration by parts.
  5329. * Since the function is symmetric about t=0, the area under the
  5330. * right tail of the density is found by calling the function
  5331. * with -t instead of t.
  5332. *
  5333. * ACCURACY:
  5334. *
  5335. * Tested at random 1 <= k <= 25. The "domain" refers to t.
  5336. * Relative error:
  5337. * arithmetic domain # trials peak rms
  5338. * IEEE -100,-2 50000 5.9e-15 1.4e-15
  5339. * IEEE -2,100 500000 2.7e-15 4.9e-17
  5340. */
  5341. /* stdtri.c
  5342. *
  5343. * Functional inverse of Student's t distribution
  5344. *
  5345. *
  5346. *
  5347. * SYNOPSIS:
  5348. *
  5349. * double p, t, stdtri();
  5350. * int k;
  5351. *
  5352. * t = stdtri( k, p );
  5353. *
  5354. *
  5355. * DESCRIPTION:
  5356. *
  5357. * Given probability p, finds the argument t such that stdtr(k,t)
  5358. * is equal to p.
  5359. *
  5360. * ACCURACY:
  5361. *
  5362. * Tested at random 1 <= k <= 100. The "domain" refers to p:
  5363. * Relative error:
  5364. * arithmetic domain # trials peak rms
  5365. * IEEE .001,.999 25000 5.7e-15 8.0e-16
  5366. * IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
  5367. */
  5368. /* struve.c
  5369. *
  5370. * Struve function
  5371. *
  5372. *
  5373. *
  5374. * SYNOPSIS:
  5375. *
  5376. * double v, x, y, struve();
  5377. *
  5378. * y = struve( v, x );
  5379. *
  5380. *
  5381. *
  5382. * DESCRIPTION:
  5383. *
  5384. * Computes the Struve function Hv(x) of order v, argument x.
  5385. * Negative x is rejected unless v is an integer.
  5386. *
  5387. * This module also contains the hypergeometric functions 1F2
  5388. * and 3F0 and a routine for the Bessel function Yv(x) with
  5389. * noninteger v.
  5390. *
  5391. *
  5392. *
  5393. * ACCURACY:
  5394. *
  5395. * Not accurately characterized, but spot checked against tables.
  5396. *
  5397. */
  5398. /* tan.c
  5399. *
  5400. * Circular tangent
  5401. *
  5402. *
  5403. *
  5404. * SYNOPSIS:
  5405. *
  5406. * double x, y, tan();
  5407. *
  5408. * y = tan( x );
  5409. *
  5410. *
  5411. *
  5412. * DESCRIPTION:
  5413. *
  5414. * Returns the circular tangent of the radian argument x.
  5415. *
  5416. * Range reduction is modulo pi/4. A rational function
  5417. * x + x**3 P(x**2)/Q(x**2)
  5418. * is employed in the basic interval [0, pi/4].
  5419. *
  5420. *
  5421. *
  5422. * ACCURACY:
  5423. *
  5424. * Relative error:
  5425. * arithmetic domain # trials peak rms
  5426. * DEC +-1.07e9 44000 4.1e-17 1.0e-17
  5427. * IEEE +-1.07e9 30000 2.9e-16 8.1e-17
  5428. *
  5429. * ERROR MESSAGES:
  5430. *
  5431. * message condition value returned
  5432. * tan total loss x > 1.073741824e9 0.0
  5433. *
  5434. */
  5435. /* cot.c
  5436. *
  5437. * Circular cotangent
  5438. *
  5439. *
  5440. *
  5441. * SYNOPSIS:
  5442. *
  5443. * double x, y, cot();
  5444. *
  5445. * y = cot( x );
  5446. *
  5447. *
  5448. *
  5449. * DESCRIPTION:
  5450. *
  5451. * Returns the circular cotangent of the radian argument x.
  5452. *
  5453. * Range reduction is modulo pi/4. A rational function
  5454. * x + x**3 P(x**2)/Q(x**2)
  5455. * is employed in the basic interval [0, pi/4].
  5456. *
  5457. *
  5458. *
  5459. * ACCURACY:
  5460. *
  5461. * Relative error:
  5462. * arithmetic domain # trials peak rms
  5463. * IEEE +-1.07e9 30000 2.9e-16 8.2e-17
  5464. *
  5465. *
  5466. * ERROR MESSAGES:
  5467. *
  5468. * message condition value returned
  5469. * cot total loss x > 1.073741824e9 0.0
  5470. * cot singularity x = 0 INFINITY
  5471. *
  5472. */
  5473. /* tandg.c
  5474. *
  5475. * Circular tangent of argument in degrees
  5476. *
  5477. *
  5478. *
  5479. * SYNOPSIS:
  5480. *
  5481. * double x, y, tandg();
  5482. *
  5483. * y = tandg( x );
  5484. *
  5485. *
  5486. *
  5487. * DESCRIPTION:
  5488. *
  5489. * Returns the circular tangent of the argument x in degrees.
  5490. *
  5491. * Range reduction is modulo pi/4. A rational function
  5492. * x + x**3 P(x**2)/Q(x**2)
  5493. * is employed in the basic interval [0, pi/4].
  5494. *
  5495. *
  5496. *
  5497. * ACCURACY:
  5498. *
  5499. * Relative error:
  5500. * arithmetic domain # trials peak rms
  5501. * DEC 0,10 8000 3.4e-17 1.2e-17
  5502. * IEEE 0,10 30000 3.2e-16 8.4e-17
  5503. *
  5504. * ERROR MESSAGES:
  5505. *
  5506. * message condition value returned
  5507. * tandg total loss x > 8.0e14 (DEC) 0.0
  5508. * x > 1.0e14 (IEEE)
  5509. * tandg singularity x = 180 k + 90 MAXNUM
  5510. */
  5511. /* cotdg.c
  5512. *
  5513. * Circular cotangent of argument in degrees
  5514. *
  5515. *
  5516. *
  5517. * SYNOPSIS:
  5518. *
  5519. * double x, y, cotdg();
  5520. *
  5521. * y = cotdg( x );
  5522. *
  5523. *
  5524. *
  5525. * DESCRIPTION:
  5526. *
  5527. * Returns the circular cotangent of the argument x in degrees.
  5528. *
  5529. * Range reduction is modulo pi/4. A rational function
  5530. * x + x**3 P(x**2)/Q(x**2)
  5531. * is employed in the basic interval [0, pi/4].
  5532. *
  5533. *
  5534. * ERROR MESSAGES:
  5535. *
  5536. * message condition value returned
  5537. * cotdg total loss x > 8.0e14 (DEC) 0.0
  5538. * x > 1.0e14 (IEEE)
  5539. * cotdg singularity x = 180 k MAXNUM
  5540. */
  5541. /* tanh.c
  5542. *
  5543. * Hyperbolic tangent
  5544. *
  5545. *
  5546. *
  5547. * SYNOPSIS:
  5548. *
  5549. * double x, y, tanh();
  5550. *
  5551. * y = tanh( x );
  5552. *
  5553. *
  5554. *
  5555. * DESCRIPTION:
  5556. *
  5557. * Returns hyperbolic tangent of argument in the range MINLOG to
  5558. * MAXLOG.
  5559. *
  5560. * A rational function is used for |x| < 0.625. The form
  5561. * x + x**3 P(x)/Q(x) of Cody _& Waite is employed.
  5562. * Otherwise,
  5563. * tanh(x) = sinh(x)/cosh(x) = 1 - 2/(exp(2x) + 1).
  5564. *
  5565. *
  5566. *
  5567. * ACCURACY:
  5568. *
  5569. * Relative error:
  5570. * arithmetic domain # trials peak rms
  5571. * DEC -2,2 50000 3.3e-17 6.4e-18
  5572. * IEEE -2,2 30000 2.5e-16 5.8e-17
  5573. *
  5574. */
  5575. /* unity.c
  5576. *
  5577. * Relative error approximations for function arguments near
  5578. * unity.
  5579. *
  5580. * log1p(x) = log(1+x)
  5581. * expm1(x) = exp(x) - 1
  5582. * cosm1(x) = cos(x) - 1
  5583. *
  5584. */
  5585. /* yn.c
  5586. *
  5587. * Bessel function of second kind of integer order
  5588. *
  5589. *
  5590. *
  5591. * SYNOPSIS:
  5592. *
  5593. * double x, y, yn();
  5594. * int n;
  5595. *
  5596. * y = yn( n, x );
  5597. *
  5598. *
  5599. *
  5600. * DESCRIPTION:
  5601. *
  5602. * Returns Bessel function of order n, where n is a
  5603. * (possibly negative) integer.
  5604. *
  5605. * The function is evaluated by forward recurrence on
  5606. * n, starting with values computed by the routines
  5607. * y0() and y1().
  5608. *
  5609. * If n = 0 or 1 the routine for y0 or y1 is called
  5610. * directly.
  5611. *
  5612. *
  5613. *
  5614. * ACCURACY:
  5615. *
  5616. *
  5617. * Absolute error, except relative
  5618. * when y > 1:
  5619. * arithmetic domain # trials peak rms
  5620. * DEC 0, 30 2200 2.9e-16 5.3e-17
  5621. * IEEE 0, 30 30000 3.4e-15 4.3e-16
  5622. *
  5623. *
  5624. * ERROR MESSAGES:
  5625. *
  5626. * message condition value returned
  5627. * yn singularity x = 0 MAXNUM
  5628. * yn overflow MAXNUM
  5629. *
  5630. * Spot checked against tables for x, n between 0 and 100.
  5631. *
  5632. */
  5633. /* zeta.c
  5634. *
  5635. * Riemann zeta function of two arguments
  5636. *
  5637. *
  5638. *
  5639. * SYNOPSIS:
  5640. *
  5641. * double x, q, y, zeta();
  5642. *
  5643. * y = zeta( x, q );
  5644. *
  5645. *
  5646. *
  5647. * DESCRIPTION:
  5648. *
  5649. *
  5650. *
  5651. * inf.
  5652. * - -x
  5653. * zeta(x,q) = > (k+q)
  5654. * -
  5655. * k=0
  5656. *
  5657. * where x > 1 and q is not a negative integer or zero.
  5658. * The Euler-Maclaurin summation formula is used to obtain
  5659. * the expansion
  5660. *
  5661. * n
  5662. * - -x
  5663. * zeta(x,q) = > (k+q)
  5664. * -
  5665. * k=1
  5666. *
  5667. * 1-x inf. B x(x+1)...(x+2j)
  5668. * (n+q) 1 - 2j
  5669. * + --------- - ------- + > --------------------
  5670. * x-1 x - x+2j+1
  5671. * 2(n+q) j=1 (2j)! (n+q)
  5672. *
  5673. * where the B2j are Bernoulli numbers. Note that (see zetac.c)
  5674. * zeta(x,1) = zetac(x) + 1.
  5675. *
  5676. *
  5677. *
  5678. * ACCURACY:
  5679. *
  5680. *
  5681. *
  5682. * REFERENCE:
  5683. *
  5684. * Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals,
  5685. * Series, and Products, p. 1073; Academic Press, 1980.
  5686. *
  5687. */
  5688. /* zetac.c
  5689. *
  5690. * Riemann zeta function
  5691. *
  5692. *
  5693. *
  5694. * SYNOPSIS:
  5695. *
  5696. * double x, y, zetac();
  5697. *
  5698. * y = zetac( x );
  5699. *
  5700. *
  5701. *
  5702. * DESCRIPTION:
  5703. *
  5704. *
  5705. *
  5706. * inf.
  5707. * - -x
  5708. * zetac(x) = > k , x > 1,
  5709. * -
  5710. * k=2
  5711. *
  5712. * is related to the Riemann zeta function by
  5713. *
  5714. * Riemann zeta(x) = zetac(x) + 1.
  5715. *
  5716. * Extension of the function definition for x < 1 is implemented.
  5717. * Zero is returned for x > log2(MAXNUM).
  5718. *
  5719. * An overflow error may occur for large negative x, due to the
  5720. * gamma function in the reflection formula.
  5721. *
  5722. * ACCURACY:
  5723. *
  5724. * Tabulated values have full machine accuracy.
  5725. *
  5726. * Relative error:
  5727. * arithmetic domain # trials peak rms
  5728. * IEEE 1,50 10000 9.8e-16 1.3e-16
  5729. * DEC 1,50 2000 1.1e-16 1.9e-17
  5730. *
  5731. *
  5732. */