spe.pas 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. {
  2. This file is part of the Numlib package.
  3. Copyright (c) 1986-2000 by
  4. Kees van Ginneken, Wil Kortsmit and Loek van Reij of the
  5. Computational centre of the Eindhoven University of Technology
  6. FPC port Code by Marco van de Voort ([email protected])
  7. documentation by Michael van Canneyt ([email protected])
  8. Special functions. (Currently, most of these functions only work for
  9. ArbFloat=REAL/DOUBLE, not for Extended(at least not at full
  10. precision, implement the tables in the diverse functions
  11. for extended)
  12. See the file COPYING.FPC, included in this distribution,
  13. for details about the copyright.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. **********************************************************************}
  18. unit spe;
  19. {$I DIRECT.INC}
  20. interface
  21. uses typ;
  22. { Calculate modified Besselfunction "of the first kind" I0(x) }
  23. function spebi0(x: ArbFloat): ArbFloat;
  24. { Calculate modified Besselfunction "of the first kind" I1(x) }
  25. function spebi1(x: ArbFloat): ArbFloat;
  26. { Calculate Besselfunction "of the first kind" J0(x) }
  27. function spebj0(x: ArbFloat): ArbFloat;
  28. { Calculate Besselfunction "of the first kind" J1(x) }
  29. function spebj1(x: ArbFloat): ArbFloat;
  30. { Calculate modified Besselfunction "of the second kind" K0(x) }
  31. function spebk0(x: ArbFloat): ArbFloat;
  32. { Calculate modified Besselfunction "of the second kind" K1(x) }
  33. function spebk1(x: ArbFloat): ArbFloat;
  34. { Calculate Besselfunction "of the second kind" Y0(x) }
  35. function speby0(x: ArbFloat): ArbFloat;
  36. { Calculate Besselfunction "of the second kind" Y1(x) }
  37. function speby1(x: ArbFloat): ArbFloat;
  38. { Entier function, calculates first integer greater or equal than X}
  39. function speent(x: ArbFloat): longint;
  40. { Errorfunction ( 2/sqrt(pi)* Int(t,0,pi,exp(sqr(t)) )}
  41. function speerf(x: ArbFloat): ArbFloat;
  42. { Errorfunction's complement ( 2/sqrt(pi)* Int(t,pi,inf,exp(sqr(t)) )}
  43. function speefc(x: ArbFloat): ArbFloat;
  44. { Function to calculate the Gamma function ( int(t,0,inf,t^(x-1)*exp(-t)) }
  45. function spegam(x: ArbFloat): ArbFloat;
  46. { Function to calculate the natural logaritm of the Gamma function}
  47. function spelga(x: ArbFloat): ArbFloat;
  48. { "Calculates" the maximum of two ArbFloat values }
  49. function spemax(a, b: ArbFloat): ArbFloat;
  50. { Calculates the functionvalue of a polynomalfunction with n coefficients in a
  51. for variable X }
  52. function spepol(x: ArbFloat; var a: ArbFloat; n: ArbInt): ArbFloat;
  53. { Calc a^b with a and b real numbers}
  54. function spepow(a, b: ArbFloat): ArbFloat;
  55. { Returns sign of x (-1 for x<0, 0 for x=0 and 1 for x>0) }
  56. function spesgn(x: ArbFloat): ArbInt;
  57. { ArcSin(x) }
  58. function spears(x: ArbFloat): ArbFloat;
  59. { ArcCos(x) }
  60. function spearc(x: ArbFloat): ArbFloat;
  61. { Sinh(x) }
  62. function spesih(x: ArbFloat): ArbFloat;
  63. { Cosh(x) }
  64. function specoh(x: ArbFloat): ArbFloat;
  65. { Tanh(x) }
  66. function spetah(x: ArbFloat): ArbFloat;
  67. { ArcSinH(x) }
  68. function speash(x: ArbFloat): ArbFloat;
  69. { ArcCosh(x) }
  70. function speach(x: ArbFloat): ArbFloat;
  71. { ArcTanH(x) }
  72. function speath(x: ArbFloat): ArbFloat;
  73. implementation
  74. function spebi0(x: ArbFloat): ArbFloat;
  75. const
  76. xvsmall = 3.2e-9;
  77. a1 : array[0..23] of ArbFloat =
  78. ( 3.08508322553671039e-1, -1.86478066609466760e-1,
  79. 1.57686843969995904e-1, -1.28895621330524993e-1,
  80. 9.41616340200868389e-2, -6.04316795007737183e-2,
  81. 3.41505388391452157e-2, -1.71317947935716536e-2,
  82. 7.70061052263382555e-3, -3.12923286656374358e-3,
  83. 1.15888319775791686e-3, -3.93934532072526720e-4,
  84. 1.23682594989692688e-4, -3.60645571444886286e-5,
  85. 9.81395862769787105e-6, -2.50298975966588680e-6,
  86. 6.00566861079330132e-7, -1.36042013507151017e-7,
  87. 2.92096163521178835e-8, -5.94856273204259507e-9,
  88. 1.13415934215369209e-9, -2.10071360134551962e-10,
  89. 4.44484446637868974e-11,-7.48150165756234957e-12);
  90. a2 : array[0..26] of ArbFloat =
  91. ( 1.43431781856850311e-1, -3.71571542566085323e-2,
  92. 1.44861237337359455e-2, -6.30121694459896307e-3,
  93. 2.89362046530968701e-3, -1.37638906941232170e-3,
  94. 6.72508592273773611e-4, -3.35833513200679384e-4,
  95. 1.70524543267970595e-4, -8.74354291104467762e-5,
  96. 4.48739019580173804e-5, -2.28278155280668483e-5,
  97. 1.14032404021741277e-5, -5.54917762110482949e-6,
  98. 2.61457634142262604e-6, -1.18752840689765504e-6,
  99. 5.18632519069546106e-7, -2.17653548816447667e-7,
  100. 8.75291839187305722e-8, -3.34900221934314738e-8,
  101. 1.24131668344616429e-8, -4.66215489983794905e-9,
  102. 1.58599776268172290e-9, -3.80370174256271589e-10,
  103. 1.23188158175419302e-10,-8.46900307934754898e-11,
  104. 2.45185252963941089e-11);
  105. a3: array[0..19] of ArbFloat =
  106. ( 4.01071065066847416e-1, 2.18216817211694382e-3,
  107. 5.59848253337377763e-5, 2.79770701849785597e-6,
  108. 2.17160501061222148e-7, 2.36884434055843528e-8,
  109. 3.44345025431425567e-9, 6.47994117793472057e-10,
  110. 1.56147127476528831e-10, 4.82726630988879388e-11,
  111. 1.89599322920800794e-11, 1.05863621425699789e-11,
  112. 8.27719401266046976e-12, 2.82807056475555021e-12,
  113. -4.34624739357691085e-12,-4.29417106720584499e-12,
  114. 4.30812577328136192e-13, 1.44572313799118029e-12,
  115. 4.73229306831831040e-14,-1.95679809047625728e-13);
  116. var t : ArbFloat;
  117. begin
  118. t:=abs(x);
  119. if t <=xvsmall
  120. then
  121. spebi0:=1
  122. else
  123. if t <= 4
  124. then
  125. spebi0 := exp(t)*spepol(t/2-1, a1[0], SizeOf(a1) div SizeOf(ArbFloat) -1)
  126. else
  127. if t <= 12
  128. then
  129. spebi0:=exp(t)*spepol(t/4-2, a2[0], SizeOf(a2) div SizeOf(ArbFloat) -1)
  130. else { t > 12}
  131. spebi0:=(exp(t)/sqrt(t))*
  132. spepol(24/t-1, a3[0], SizeOf(a3) div SizeOf(ArbFloat) -1)
  133. end; {spebi0}
  134. function spebi1(x: ArbFloat): ArbFloat;
  135. const xvsmall = 3.2e-9;
  136. a1: array[0..11] of ArbFloat =
  137. ( 1.19741654963670236e+0, 9.28758890114609554e-1,
  138. 2.68657659522092832e-1, 4.09286371827770484e-2,
  139. 3.84763940423809498e-3, 2.45224314039278904e-4,
  140. 1.12849795779951847e-5, 3.92368710996392755e-7,
  141. 1.06662712314503955e-8, 2.32856921884663846e-10,
  142. 4.17372709788222413e-12,6.24387910353848320e-14);
  143. a2: array[0..26] of ArbFloat =
  144. ( 1.34142493292698178e-1, -2.99140923897405570e-2,
  145. 9.76021102528646704e-3, -3.40759647928956354e-3,
  146. 1.17313412855965374e-3, -3.67626180992174570e-4,
  147. 8.47999438119288094e-5, 5.21557319070236939e-6,
  148. -2.62051678511418163e-5, 2.47493270133518925e-5,
  149. -1.79026222757948636e-5, 1.13818992442463952e-5,
  150. -6.63144162982509821e-6, 3.60186151617732531e-6,
  151. -1.83910206626348772e-6, 8.86951515545183908e-7,
  152. -4.05456611578551130e-7, 1.76305222240064495e-7,
  153. -7.28978293484163628e-8, 2.84961041291017650e-8,
  154. -1.07563514207617768e-8, 4.11321223904934809e-9,
  155. -1.41575617446629553e-9, 3.38883570696523350e-10,
  156. -1.10970391104678003e-10, 7.79929176497056645e-11,
  157. -2.27061376122617856e-11);
  158. a3: array[0..19] of ArbFloat =
  159. ( 3.92624494204116555e-1, -6.40545360348237412e-3,
  160. -9.12475535508497109e-5, -3.82795135453556215e-6,
  161. -2.72684545741400871e-7, -2.82537120880041703e-8,
  162. -3.96757162863209348e-9, -7.28107961041827952e-10,
  163. -1.72060490748583241e-10,-5.23524129533553498e-11,
  164. -2.02947854602758139e-11,-1.11795516742222899e-11,
  165. -8.69631766630563635e-12,-3.05957293450420224e-12,
  166. 4.42966462319664333e-12, 4.47735589657057690e-12,
  167. -3.95353303949377536e-13,-1.48765082315961139e-12,
  168. -5.77176811730370560e-14, 1.99448557598015488e-13);
  169. var t : ArbFloat;
  170. begin
  171. t:=abs(x);
  172. if t <= xvsmall
  173. then
  174. spebi1:=x/2
  175. else
  176. if t <= 4
  177. then
  178. spebi1:=x*spepol(sqr(t)/8-1, a1[0], sizeof(a1) div sizeof(ArbFloat)-1)
  179. else
  180. if t <= 12
  181. then
  182. spebi1:=
  183. exp(t)*spepol(t/4-2, a2[0], sizeof(a2) div sizeof(ArbFloat)-1)*spesgn(x)
  184. else { t > 12}
  185. spebi1:=
  186. (exp(t)/sqrt(t))*
  187. spepol(24/t-1, a3[0], sizeof(a3) div sizeof(ArbFloat)-1)*spesgn(x)
  188. end; {spebi1}
  189. function spebj0(x: ArbFloat): ArbFloat;
  190. const
  191. xvsmall = 3.2e-9;
  192. tbpi = 6.36619772367581343e-1;
  193. a1 : array[0..5] of ArbFloat =
  194. ( 1.22200000000000000e-17, -1.94383469000000000e-12,
  195. 7.60816359241900000e-8, -4.60626166206275050e-4,
  196. 1.58067102332097261e-1, -8.72344235285222129e-3);
  197. b1 : array[0..5] of ArbFloat =
  198. ( - 7.58850000000000000e-16, 7.84869631400000000e-11,
  199. - 1.76194690776215000e-6, 4.81918006946760450e-3,
  200. - 3.70094993872649779e-1, 1.57727971474890120e-1);
  201. c1 : array[0..4] of ArbFloat =
  202. ( 4.12532100000000000e-14, - 2.67925353056000000e-9,
  203. 3.24603288210050800e-5, - 3.48937694114088852e-2,
  204. 2.65178613203336810e-1);
  205. d1 : array[0..13] of ArbFloat =
  206. ( 9.99457275788251954e-1, -5.36367319213004570e-4,
  207. 6.13741608010926000e-6, -2.05274481565160000e-7,
  208. 1.28037614434400000e-8, -1.21211819632000000e-9,
  209. 1.55005642880000000e-10,-2.48827276800000000e-11,
  210. 4.78702080000000000e-12,-1.06365696000000000e-12,
  211. 2.45294080000000000e-13,-6.41843200000000000e-14,
  212. 3.34028800000000000e-14,-1.17964800000000000e-14);
  213. d2 : array[0..16] of ArbFloat =
  214. ( -1.55551138795135187e-2, 6.83314909934390000e-5,
  215. -1.47713883264594000e-6, 7.10621485930000000e-8,
  216. -5.66871613024000000e-9, 6.43278173280000000e-10,
  217. -9.47034774400000000e-11, 1.70330918400000000e-11,
  218. -3.59094272000000000e-12, 8.59855360000000000e-13,
  219. -2.28807680000000000e-13, 6.95193600000000000e-14,
  220. -2.27942400000000000e-14, 4.75136000000000000e-15,
  221. -1.14688000000000000e-15, 2.12992000000000000e-15,
  222. -9.83040000000000000e-16);
  223. var t, g, y, t2, a, b, c, cx, sx : ArbFloat;
  224. i, bov : ArbInt;
  225. begin
  226. t:=abs(x);
  227. if t<=xvsmall
  228. then
  229. spebj0:=1
  230. else
  231. if t<=8
  232. then
  233. begin
  234. t:=0.03125*sqr(t)-1; t2:=2*t;
  235. b:=0; c:=0;
  236. bov:=sizeof(a1) div sizeof(ArbFloat) - 1;
  237. for i:=0 to bov do
  238. begin
  239. a:=t2*c-b+a1[i];
  240. if i<5
  241. then
  242. b:=t2*a-c+b1[i]
  243. else
  244. spebj0:=t*a-c+b1[i];
  245. if i<bov
  246. then
  247. c:=t2*b-a+c1[i]
  248. else
  249. if i<5
  250. then
  251. spebj0:=t*b-a+c1[i]
  252. end {i}
  253. end {abs(x)<=8}
  254. else
  255. begin
  256. g:=t-1/(2*tbpi); y:=sqrt(tbpi/t);
  257. cx:=cos(g)*y; sx:=-sin(g)*y*8/t;
  258. t:=128/sqr(t)-1;
  259. spebj0:=cx*spepol(t, d1[0], sizeof(d1) div sizeof(ArbFloat) - 1)
  260. + sx*spepol(t, d2[0], sizeof(d2) div sizeof(ArbFloat) - 1)
  261. end {abs(x)>8}
  262. end {spebj0};
  263. function spebj1(x: ArbFloat): ArbFloat;
  264. const
  265. xvsmall = 3.2e-9;
  266. tbpi = 6.36619772367581343e-1;
  267. a1 : array[0..5] of ArbFloat =
  268. ( 2.95000000000000000e-18, -5.77740420000000000e-13,
  269. 2.94970700727800000e-8, -2.60444389348580680e-4,
  270. 1.77709117239728283e-1, -1.19180116054121687e+0);
  271. b1 : array[0..5] of ArbFloat =
  272. ( -1.95540000000000000e-16, 2.52812366400000000e-11,
  273. -7.61758780540030000e-7, 3.24027018268385747e-3,
  274. -6.61443934134543253e-1, 6.48358770605264921e-1);
  275. c1 : array[0..4] of ArbFloat =
  276. ( 1.13857200000000000e-14, -9.42421298160000000e-10,
  277. 1.58870192399321300e-5, -2.91755248061542077e-2,
  278. 1.28799409885767762e+0);
  279. d1 : array[0..13] of ArbFloat =
  280. ( 1.00090702627808217e+0, 8.98804941670557880e-4,
  281. -7.95969469843846000e-6, 2.45367662227560000e-7,
  282. -1.47085129889600000e-8, 1.36030580128000000e-9,
  283. -1.71310758400000000e-10, 2.72040729600000000e-11,
  284. -5.19113984000000000e-12, 1.14622464000000000e-12,
  285. -2.63372800000000000e-13, 6.86387200000000000e-14,
  286. -3.54508800000000000e-14, 1.24928000000000000e-14);
  287. d2 : array[0..15] of ArbFloat =
  288. ( 4.67768740274489776e-2, -9.62145882205441600e-5,
  289. 1.82120185123076000e-6, -8.29196070929200000e-8,
  290. 6.42013250344000000e-9, -7.15110504800000000e-10,
  291. 1.03950931840000000e-10, -1.85248000000000000e-11,
  292. 3.87554432000000000e-12, -9.23228160000000000e-13,
  293. 2.50224640000000000e-13, -7.43936000000000000e-14,
  294. 1.75718400000000000e-14, -4.83328000000000000e-15,
  295. 5.32480000000000000e-15, -2.29376000000000000e-15);
  296. var t, g, y, t2, a, b, c, cx, sx : ArbFloat;
  297. i, bov : ArbInt;
  298. begin
  299. t:=abs(x);
  300. if t<xvsmall
  301. then
  302. spebj1:=x/2
  303. else
  304. if t<=8
  305. then
  306. begin
  307. t:=0.03125*sqr(t)-1; t2:=2*t;
  308. b:=0; c:=0;
  309. bov:=sizeof(a1) div sizeof(ArbFloat) - 1;
  310. for i:=0 to bov do
  311. begin
  312. a:=t2*c-b+a1[i];
  313. if i<bov
  314. then
  315. begin
  316. b:=t2*a-c+b1[i];
  317. c:=t2*b-a+c1[i]
  318. end
  319. else
  320. spebj1:=(x/8)*(t*a-c+b1[i])
  321. end {i}
  322. end {abs(x)<=8}
  323. else
  324. begin
  325. g:=t-1.5/tbpi; y:=sqrt(tbpi/t)*spesgn(x);
  326. cx:=cos(g)*y; sx:=-sin(g)*y*8/t;
  327. t:=128/sqr(t)-1;
  328. spebj1:=cx*spepol(t, d1[0], sizeof(d1) div sizeof(ArbFloat) - 1)
  329. + sx*spepol(t, d2[0], sizeof(d2) div sizeof(ArbFloat) - 1)
  330. end {abs(x)>8}
  331. end {spebj1};
  332. function spebk0(x: ArbFloat): ArbFloat;
  333. const
  334. egam = 0.57721566490153286;
  335. xvsmall = 3.2e-9;
  336. highexp = 745;
  337. a0: array[0..7] of ArbFloat =
  338. ( 1.12896092945412762e+0, 1.32976966478338191e-1,
  339. 4.07157485171389048e-3, 5.59702338227915383e-5,
  340. 4.34562671546158210e-7, 2.16382411824721532e-9,
  341. 7.49110736894134794e-12, 1.90674197514561280e-14);
  342. a1: array[0..8] of ArbFloat =
  343. ( 2.61841879258687055e-1, 1.52436921799395196e-1,
  344. 6.63513979313943827e-3, 1.09534292632401542e-4,
  345. 9.57878493265929443e-7, 5.19906865800665633e-9,
  346. 1.92405264219706684e-11, 5.16867886946332160e-14,
  347. 1.05407718191360000e-16);
  348. a2: array[0..22] of ArbFloat =
  349. ( 9.58210053294896496e-1, -1.42477910128828254e-1,
  350. 3.23582010649653009e-2, -8.27780350351692662e-3,
  351. 2.24709729617770471e-3, -6.32678357460594866e-4,
  352. 1.82652460089342789e-4, -5.37101208898441760e-5,
  353. 1.60185974149720562e-5, -4.83134250336922161e-6,
  354. 1.47055796078231691e-6, -4.51017292375200017e-7,
  355. 1.39217270224614153e-7, -4.32185089841834127e-8,
  356. 1.34790467361340101e-8, -4.20597329258249948e-9,
  357. 1.32069362385968867e-9, -4.33326665618780914e-10,
  358. 1.37999268074442719e-10, -3.19241059198852137e-11,
  359. 9.74410152270679245e-12, -7.83738609108569293e-12,
  360. 2.57466288575820595e-12);
  361. a3: array[0..22] of ArbFloat =
  362. ( 6.97761598043851776e-1, -1.08801882084935132e-1,
  363. 2.56253646031960321e-2, -6.74459607940169198e-3,
  364. 1.87292939725962385e-3, -5.37145622971910027e-4,
  365. 1.57451516235860573e-4, -4.68936653814896712e-5,
  366. 1.41376509343622727e-5, -4.30373871727268511e-6,
  367. 1.32052261058932425e-6, -4.07851207862189007e-7,
  368. 1.26672629417567360e-7, -3.95403255713518420e-8,
  369. 1.23923137898346852e-8, -3.88349705250555658e-9,
  370. 1.22424982779432970e-9, -4.03424607871960089e-10,
  371. 1.28905587479980147e-10,-2.97787564633235128e-11,
  372. 9.11109430833001267e-12,-7.39672783987933184e-12,
  373. 2.43538242247537459e-12);
  374. a4: array[0..16] of ArbFloat =
  375. ( 1.23688664769425422e+0, -1.72683652385321641e-2,
  376. -9.25551464765637133e-4, -9.02553345187404564e-5,
  377. -6.31692398333746470e-6, -7.69177622529272933e-7,
  378. -4.16044811174114579e-8, -9.41555321137176073e-9,
  379. 1.75359321273580603e-10, -2.22829582288833265e-10,
  380. 3.49564293256545992e-11, -1.11391758572647639e-11,
  381. 2.85481235167705907e-12, -7.31344482663931904e-13,
  382. 2.06328892562554880e-13, -1.28108310826991616e-13,
  383. 4.43741979886551040e-14);
  384. var t: ArbFloat;
  385. begin
  386. if x<=0
  387. then
  388. RunError(401);
  389. if x<=xvsmall
  390. then
  391. spebk0:=-(ln(x/2)+egam)
  392. else
  393. if x<=1
  394. then
  395. begin
  396. t:=2*sqr(x)-1;
  397. spebk0:=-ln(x)*spepol(t, a0[0], sizeof(a0) div sizeof(ArbFloat) - 1)
  398. + spepol(t, a1[0], sizeof(a1) div sizeof(ArbFloat) - 1)
  399. end
  400. else
  401. if x<=2
  402. then
  403. spebk0:=exp(-x)*spepol(2*x-3, a2[0], sizeof(a2) div sizeof(ArbFloat) - 1)
  404. else
  405. if x<=4
  406. then
  407. spebk0:=exp(-x)*spepol(x-3, a3[0], sizeof(a3) div sizeof(ArbFloat) - 1)
  408. else
  409. if x <= highexp
  410. then
  411. spebk0:=exp(-x)*
  412. spepol(10/(1+x)-1, a4[0], sizeof(a4) div sizeof(ArbFloat) - 1)/sqrt(x)
  413. else
  414. spebk0:=0
  415. end; {spebk0}
  416. function spebk1(x: ArbFloat): ArbFloat;
  417. const
  418. xsmall = 7.9e-10;
  419. highexp = 745;
  420. a0: array[0..7] of ArbFloat =
  421. ( 5.31907865913352762e-1, 3.25725988137110495e-2,
  422. 6.71642805873498653e-4, 6.95300274548206237e-6,
  423. 4.32764823642997753e-8, 1.79784792380155752e-10,
  424. 5.33888268665658944e-13, 1.18964962439910400e-15);
  425. a1: array[0..7] of ArbFloat =
  426. ( 3.51825828289325536e-1, 4.50490442966943726e-2,
  427. 1.20333585658219028e-3, 1.44612432533006139e-5,
  428. 9.96686689273781531e-8, 4.46828628435618679e-10,
  429. 1.40917103024514301e-12, 3.29881058019865600e-15);
  430. a2: array[0..23] of ArbFloat =
  431. ( 1.24316587355255299e+0, -2.71910714388689413e-1,
  432. 8.20250220860693888e-2, -2.62545818729427417e-2,
  433. 8.57388087067410089e-3, -2.82450787841655951e-3,
  434. 9.34594154387642940e-4, -3.10007681013626626e-4,
  435. 1.02982746700060730e-4, -3.42424912211942134e-5,
  436. 1.13930169202553526e-5, -3.79227698821142908e-6,
  437. 1.26265578331941923e-6, -4.20507152338934956e-7,
  438. 1.40138351985185509e-7, -4.66928912168020101e-8,
  439. 1.54456653909012693e-8, -5.13783508140332214e-9,
  440. 1.82808381381205361e-9, -6.15211416898895086e-10,
  441. 1.28044023949946257e-10, -4.02591066627023831e-11,
  442. 4.27404330568767242e-11, -1.46639291782948454e-11);
  443. a3: array[0..23] of ArbFloat =
  444. ( 8.06563480128786903e-1, -1.60052611291327173e-1,
  445. 4.58591528414023064e-2, -1.42363136684423646e-2,
  446. 4.55865751206724687e-3, -1.48185472032688523e-3,
  447. 4.85707174778663652e-4, -1.59994873621599146e-4,
  448. 5.28712919123131781e-5, -1.75089594354079944e-5,
  449. 5.80692311842296724e-6, -1.92794586996432593e-6,
  450. 6.40581814037398274e-7, -2.12969229346310343e-7,
  451. 7.08723366696569880e-8, -2.35855618461025265e-8,
  452. 7.79421651144832709e-9, -2.59039399308009059e-9,
  453. 9.20781685906110546e-10, -3.09667392343245062e-10,
  454. 6.44913423545894175e-11, -2.02680401514735862e-11,
  455. 2.14736751065133220e-11, -7.36478297050421658e-12);
  456. a4: array[0..16] of ArbFloat =
  457. ( 1.30387573604230402e+0, 5.44845254318931612e-2,
  458. 4.31639434283445364e-3, 4.29973970898766831e-4,
  459. 4.04720631528495020e-5, 4.32776409784235211e-6,
  460. 4.07563856931843484e-7, 4.86651420008153956e-8,
  461. 3.82717692121438315e-9, 6.77688943857588882e-10,
  462. 6.97075379117731379e-12, 1.72026097285930936e-11,
  463. -2.60774502020271104e-12, 8.58211523713560576e-13,
  464. -2.19287104441802752e-13, 1.39321122940600320e-13,
  465. -4.77850238111580160e-14);
  466. var t: ArbFloat;
  467. begin
  468. if x<=0
  469. then
  470. RunError(402);
  471. if x<=xsmall
  472. then
  473. spebk1:=1/x
  474. else
  475. if x<=1
  476. then
  477. begin
  478. t:=2*sqr(x)-1;
  479. spebk1:=( ln(x)*spepol(t, a0[0], sizeof(a0) div sizeof(ArbFloat) - 1)
  480. -spepol(t, a1[0], sizeof(a1) div sizeof(ArbFloat) -1) )*x + 1/x
  481. end
  482. else
  483. if x<=2
  484. then
  485. spebk1:=exp(-x)*spepol(2*x-3, a2[0], sizeof(a2) div sizeof(ArbFloat) - 1)
  486. else
  487. if x<=4
  488. then
  489. spebk1:=exp(-x)*spepol(x-3, a3[0], sizeof(a3) div sizeof(ArbFloat) - 1)
  490. else
  491. if x <= highexp
  492. then
  493. spebk1:=exp(-x)*spepol(10/(1+x)-1, a4[0],
  494. sizeof(a4) div sizeof(ArbFloat) - 1)/sqrt(x)
  495. else
  496. spebk1:=0
  497. end; {spebk1}
  498. function speby0(x: ArbFloat): ArbFloat;
  499. const
  500. tbpi = 6.36619772367581343e-1;
  501. egam = 5.77215664901532861e-1;
  502. xvsmall = 3.2e-9;
  503. a1 : array[0..5] of ArbFloat =
  504. ( 3.90000000000000000e-19, -8.74734100000000000e-14,
  505. 5.24879478733000000e-9, -5.63207914105698700e-5,
  506. 4.71966895957633869e-2, 1.79034314077182663e-1);
  507. b1 : array[0..5] of ArbFloat =
  508. ( -2.69800000000000000e-17, 4.02633082000000000e-12,
  509. -1.44072332740190000e-7, 7.53113593257774230e-4,
  510. -1.77302012781143582e-1, -2.74474305529745265e-1);
  511. c1 : array[0..5] of ArbFloat =
  512. ( 1.64349000000000000e-15, -1.58375525420000000e-10,
  513. 3.20653253765480000e-6, -7.28796247955207918e-3,
  514. 2.61567346255046637e-1, -3.31461132032849417e-2);
  515. d1 : array[0..13] of ArbFloat =
  516. ( 9.99457275788251954e-1, -5.36367319213004570e-4,
  517. 6.13741608010926000e-6, -2.05274481565160000e-7,
  518. 1.28037614434400000e-8, -1.21211819632000000e-9,
  519. 1.55005642880000000e-10,-2.48827276800000000e-11,
  520. 4.78702080000000000e-12,-1.06365696000000000e-12,
  521. 2.45294080000000000e-13,-6.41843200000000000e-14,
  522. 3.34028800000000000e-14,-1.17964800000000000e-14);
  523. d2 : array[0..16] of ArbFloat =
  524. (-1.55551138795135187e-2, 6.83314909934390000e-5,
  525. -1.47713883264594000e-6, 7.10621485930000000e-8,
  526. -5.66871613024000000e-9, 6.43278173280000000e-10,
  527. -9.47034774400000000e-11, 1.70330918400000000e-11,
  528. -3.59094272000000000e-12, 8.59855360000000000e-13,
  529. -2.28807680000000000e-13, 6.95193600000000000e-14,
  530. -2.27942400000000000e-14, 4.75136000000000000e-15,
  531. -1.14688000000000000e-15, 2.12992000000000000e-15,
  532. -9.83040000000000000e-16);
  533. var t, g, y, t2, a, b, c, cx, sx : ArbFloat;
  534. i, bov : ArbInt;
  535. begin
  536. if x<=0
  537. then
  538. RunError(403);
  539. if x<=xvsmall
  540. then
  541. speby0:=(ln(x/2)+egam)*tbpi
  542. else
  543. if x<=8
  544. then
  545. begin
  546. t:=0.03125*sqr(x)-1; t2:=2*t;
  547. b:=0; c:=0;
  548. bov:=sizeof(a1) div sizeof(ArbFloat) - 1;
  549. for i:=0 to bov do
  550. begin
  551. a:=t2*c-b+a1[i];
  552. b:=t2*a-c+b1[i];
  553. if i<bov
  554. then
  555. c:=t2*b-a+c1[i]
  556. else
  557. speby0:=t*b-a+c1[i]+tbpi*spebj0(x)*ln(x)
  558. end {i}
  559. end {x<=8}
  560. else
  561. begin
  562. g:=x-1/(2*tbpi); y:=sqrt(tbpi/x);
  563. cx:=cos(g)*y*8/x; sx:=sin(g)*y;
  564. t:=128/sqr(x)-1;
  565. speby0:=sx*spepol(t, d1[0], sizeof(d1) div sizeof(ArbFloat) - 1)
  566. + cx*spepol(t, d2[0], sizeof(d2) div sizeof(ArbFloat) - 1)
  567. end {x>8}
  568. end {speby0};
  569. function speby1(x: ArbFloat): ArbFloat;
  570. const
  571. tbpi = 6.36619772367581343e-1;
  572. xsmall = 7.9e-10;
  573. a1 : array[0..5] of ArbFloat =
  574. (-6.58000000000000000e-18, 1.21143321000000000e-12,
  575. -5.68844003991900000e-8, 4.40478629867099510e-4,
  576. -2.26624991556754924e-1, -1.28697384381350001e-1);
  577. b1 : array[0..5] of ArbFloat =
  578. ( 4.27730000000000000e-16,-5.17212147300000000e-11,
  579. 1.41662436449235000e-6, -5.13164116106108479e-3,
  580. 6.75615780772187667e-1, 2.03041058859342538e-2);
  581. c1 : array[0..4] of ArbFloat =
  582. (-2.44094900000000000e-14, 1.87547032473000000e-9,
  583. -2.83046401495148000e-5, 4.23191803533369041e-2,
  584. -7.67296362886645940e-1);
  585. d1 : array[0..13] of ArbFloat =
  586. ( 1.00090702627808217e+0, 8.98804941670557880e-4,
  587. -7.95969469843846000e-6, 2.45367662227560000e-7,
  588. -1.47085129889600000e-8, 1.36030580128000000e-9,
  589. -1.71310758400000000e-10, 2.72040729600000000e-11,
  590. -5.19113984000000000e-12, 1.14622464000000000e-12,
  591. -2.63372800000000000e-13, 6.86387200000000000e-14,
  592. -3.54508800000000000e-14, 1.24928000000000000e-14);
  593. d2 : array[0..15] of ArbFloat =
  594. ( 4.67768740274489776e-2, -9.62145882205441600e-5,
  595. 1.82120185123076000e-6, -8.29196070929200000e-8,
  596. 6.42013250344000000e-9, -7.15110504800000000e-10,
  597. 1.03950931840000000e-10,-1.85248000000000000e-11,
  598. 3.87554432000000000e-12,-9.23228160000000000e-13,
  599. 2.50224640000000000e-13,-7.43936000000000000e-14,
  600. 1.75718400000000000e-14,-4.83328000000000000e-15,
  601. 5.32480000000000000e-15,-2.29376000000000000e-15);
  602. var t, g, y, t2, a, b, c, cx, sx : ArbFloat;
  603. i, bov : ArbInt;
  604. begin
  605. if x<=0
  606. then
  607. RunError(404);
  608. if x<=xsmall
  609. then
  610. speby1:=-tbpi/x
  611. else
  612. if x<=8
  613. then
  614. begin
  615. t:=0.03125*sqr(x)-1; t2:=2*t;
  616. b:=0; c:=0;
  617. bov:=sizeof(a1) div sizeof(ArbFloat) - 1;
  618. for i:=0 to bov do
  619. begin
  620. a:=t2*c-b+a1[i];
  621. if i<bov
  622. then
  623. begin
  624. b:=t2*a-c+b1[i];
  625. c:=t2*b-a+c1[i]
  626. end
  627. else
  628. if bov=3 {single}
  629. then
  630. begin
  631. b:=t2*a-c+b1[i];
  632. speby1:=(t*b-a+c1[i])*x/8 + spebj1(x)*ln(x)*tbpi - tbpi/x
  633. end
  634. else
  635. speby1:=(t*a-c+b1[i])*x/8 + spebj1(x)*ln(x)*tbpi - tbpi/x
  636. end {i}
  637. end {x<=8}
  638. else
  639. begin
  640. g:=x-3/(2*tbpi); y:=sqrt(tbpi/x);
  641. cx:=cos(g)*y*8/x; sx:=sin(g)*y;
  642. t:=128/sqr(x)-1;
  643. speby1:=sx*spepol(t, d1[0], sizeof(d1) div sizeof(ArbFloat) - 1)
  644. + cx*spepol(t, d2[0], sizeof(d2) div sizeof(ArbFloat) - 1)
  645. end {x>8}
  646. end {speby1};
  647. function speent(x : ArbFloat): longint;
  648. var tx : longint;
  649. begin
  650. tx:=trunc(x);
  651. if x>=0
  652. then
  653. speent:=tx
  654. else
  655. if x=tx
  656. then
  657. speent:=tx
  658. else
  659. speent:=tx-1
  660. end; {speent}
  661. function speerf(x : ArbFloat) : ArbFloat;
  662. const
  663. xup = 6.25;
  664. sqrtpi = 1.7724538509055160;
  665. c : array[1..18] of ArbFloat =
  666. ( 1.9449071068178803e0, 4.20186582324414e-2, -1.86866103976769e-2,
  667. 5.1281061839107e-3, -1.0683107461726e-3, 1.744737872522e-4,
  668. -2.15642065714e-5, 1.7282657974e-6, -2.00479241e-8,
  669. -1.64782105e-8, 2.0008475e-9, 2.57716e-11,
  670. -3.06343e-11, 1.9158e-12, 3.703e-13,
  671. -5.43e-14, -4.0e-15, 1.2e-15);
  672. d : array[1..17] of ArbFloat =
  673. ( 1.4831105640848036e0, -3.010710733865950e-1, 6.89948306898316e-2,
  674. -1.39162712647222e-2, 2.4207995224335e-3, -3.658639685849e-4,
  675. 4.86209844323e-5, -5.7492565580e-6, 6.113243578e-7,
  676. -5.89910153e-8, 5.2070091e-9, -4.232976e-10,
  677. 3.18811e-11, -2.2361e-12, 1.467e-13,
  678. -9.0e-15, 5.0e-16);
  679. var t, s, s1, s2, x2: ArbFloat;
  680. bovc, bovd, j: ArbInt;
  681. begin
  682. bovc:=sizeof(c) div sizeof(ArbFloat);
  683. bovd:=sizeof(d) div sizeof(ArbFloat);
  684. t:=abs(x);
  685. if t <= 2
  686. then
  687. begin
  688. x2:=sqr(x)-2;
  689. s1:=d[bovd]; s2:=0; j:=bovd-1;
  690. s:=x2*s1-s2+d[j];
  691. while j > 1 do
  692. begin
  693. s2:=s1; s1:=s; j:=j-1;
  694. s:=x2*s1-s2+d[j]
  695. end;
  696. speerf:=(s-s2)*x/2
  697. end
  698. else
  699. if t < xup
  700. then
  701. begin
  702. x2:=2-20/(t+3);
  703. s1:=c[bovc]; s2:=0; j:=bovc-1;
  704. s:=x2*s1-s2+c[j];
  705. while j > 1 do
  706. begin
  707. s2:=s1; s1:=s; j:=j-1;
  708. s:=x2*s1-s2+c[j]
  709. end;
  710. x2:=((s-s2)/(2*t))*exp(-sqr(x))/sqrtpi;
  711. speerf:=(1-x2)*spesgn(x)
  712. end
  713. else
  714. speerf:=spesgn(x)
  715. end; {speerf}
  716. function spemax(a, b: ArbFloat): ArbFloat;
  717. begin
  718. if a>b
  719. then
  720. spemax:=a
  721. else
  722. spemax:=b
  723. end; {spemax}
  724. function speefc(x : ArbFloat) : ArbFloat;
  725. const
  726. xlow = -6.25;
  727. xhigh = 27.28;
  728. c : array[0..22] of ArbFloat =
  729. ( 1.455897212750385e-1, -2.734219314954260e-1,
  730. 2.260080669166197e-1, -1.635718955239687e-1,
  731. 1.026043120322792e-1, -5.480232669380236e-2,
  732. 2.414322397093253e-2, -8.220621168415435e-3,
  733. 1.802962431316418e-3, -2.553523453642242e-5,
  734. -1.524627476123466e-4, 4.789838226695987e-5,
  735. 3.584014089915968e-6, -6.182369348098529e-6,
  736. 7.478317101785790e-7, 6.575825478226343e-7,
  737. -1.822565715362025e-7, -7.043998994397452e-8,
  738. 3.026547320064576e-8, 7.532536116142436e-9,
  739. -4.066088879757269e-9, -5.718639670776992e-10,
  740. 3.328130055126039e-10);
  741. var t, s : ArbFloat;
  742. begin
  743. if x <= xlow
  744. then
  745. speefc:=2
  746. else
  747. if x >= xhigh
  748. then
  749. speefc:=0
  750. else
  751. begin
  752. t:=1-7.5/(abs(x)+3.75);
  753. s:=exp(-x*x)*spepol(t, c[0], sizeof(c) div sizeof(ArbFloat) - 1);
  754. if x < 0
  755. then
  756. speefc:=2-s
  757. else
  758. speefc:=s
  759. end
  760. end {speefc};
  761. function spegam(x: ArbFloat): ArbFloat;
  762. const
  763. tmax = 170;
  764. a: array[0..23] of ArbFloat =
  765. ( 8.86226925452758013e-1, 1.61691987244425092e-2,
  766. 1.03703363422075456e-1, -1.34118505705967765e-2,
  767. 9.04033494028101968e-3, -2.42259538436268176e-3,
  768. 9.15785997288933120e-4, -2.96890121633200000e-4,
  769. 1.00928148823365120e-4, -3.36375833240268800e-5,
  770. 1.12524642975590400e-5, -3.75499034136576000e-6,
  771. 1.25281466396672000e-6, -4.17808776355840000e-7,
  772. 1.39383522590720000e-7, -4.64774927155200000e-8,
  773. 1.53835215257600000e-8, -5.11961333760000000e-9,
  774. 1.82243164160000000e-9, -6.13513953280000000e-10,
  775. 1.27679856640000000e-10,-4.01499750400000000e-11,
  776. 4.26560716800000000e-11,-1.46381209600000000e-11);
  777. var tvsmall, t, g: ArbFloat;
  778. m, i: ArbInt;
  779. begin
  780. if sizeof(ArbFloat) = 6
  781. then
  782. tvsmall:=2*midget
  783. else
  784. tvsmall:=midget;
  785. t:=abs(x);
  786. if t > tmax
  787. then
  788. RunError(407);
  789. if t < macheps
  790. then
  791. begin
  792. if t < tvsmall
  793. then
  794. RunError(407);
  795. spegam:=1/x
  796. end
  797. else { abs(x) >= macheps }
  798. begin
  799. m:=trunc(x);
  800. if x > 0
  801. then
  802. begin
  803. t:=x-m; m:=m-1; g:=1;
  804. if m<0
  805. then
  806. g:=g/x
  807. else
  808. if m>0
  809. then
  810. for i:=1 to m do
  811. g:=(x-i)*g
  812. end
  813. else { x < 0 }
  814. begin
  815. t:=x-m+1;
  816. if t=1
  817. then
  818. RunError(407);
  819. m:=1-m;
  820. g:=x;
  821. for i:=1 to m do
  822. g:=(i+x)*g;
  823. g:=1/g
  824. end;
  825. spegam:=spepol(2*t-1, a[0], sizeof(a) div sizeof(ArbFloat) - 1)*g
  826. end { abs(x) >= macheps }
  827. end; {spegam}
  828. function spelga(x: ArbFloat): ArbFloat;
  829. const
  830. xbig = 7.7e7;
  831. xmax = 2.559e305;
  832. lnr2pi = 9.18938533204672742e-1;
  833. a: array[0..23] of ArbFloat =
  834. ( 8.86226925452758013e-1, 1.61691987244425092e-2,
  835. 1.03703363422075456e-1, -1.34118505705967765e-2,
  836. 9.04033494028101968e-3, -2.42259538436268176e-3,
  837. 9.15785997288933120e-4, -2.96890121633200000e-4,
  838. 1.00928148823365120e-4, -3.36375833240268800e-5,
  839. 1.12524642975590400e-5, -3.75499034136576000e-6,
  840. 1.25281466396672000e-6, -4.17808776355840000e-7,
  841. 1.39383522590720000e-7, -4.64774927155200000e-8,
  842. 1.53835215257600000e-8, -5.11961333760000000e-9,
  843. 1.82243164160000000e-9, -6.13513953280000000e-10,
  844. 1.27679856640000000e-10,-4.01499750400000000e-11,
  845. 4.26560716800000000e-11,-1.46381209600000000e-11);
  846. b: array[0..5] of ArbFloat =
  847. ( 8.33271644065786580e-2, -6.16502049453716986e-6,
  848. 3.89978899876484712e-9, -6.45101975779653651e-12,
  849. 2.00201927337982364e-14, -9.94561064728159347e-17);
  850. var t, g : ArbFloat;
  851. m, i : ArbInt;
  852. begin
  853. if x <= 0
  854. then
  855. RunError(408);
  856. if x <= macheps
  857. then
  858. spelga:=-ln(x)
  859. else
  860. if x <= 15
  861. then
  862. begin
  863. m:=trunc(x); t:=x-m; m:=m-1; g:=1;
  864. if m < 0
  865. then
  866. g:=g/x
  867. else
  868. if m > 0
  869. then
  870. for i:=1 to m do
  871. g:=(x-i)*g;
  872. spelga:=ln(g*spepol(2*t-1, a[0], sizeof(a) div sizeof(ArbFloat) - 1))
  873. end
  874. else { x > 15 }
  875. if x <= xbig
  876. then
  877. spelga:=(x-0.5)*ln(x) - x + lnr2pi
  878. + spepol(450/sqr(x)-1, b[0], sizeof(b) div sizeof(ArbFloat) - 1)/x
  879. else { x > xbig }
  880. if x <= xmax
  881. then
  882. spelga:=(x-0.5)*ln(x) - x + lnr2pi
  883. else { x > xmax => x*ln(x) > giant }
  884. RunError(408)
  885. end; {spelga}
  886. function spepol(x: ArbFloat; var a: ArbFloat; n: ArbInt): ArbFloat;
  887. var pa : ^arfloat0;
  888. i : ArbInt;
  889. polx : ArbFloat;
  890. begin
  891. pa:=@a;
  892. polx:=0;
  893. for i:=n downto 0 do
  894. polx:=polx*x+pa^[i];
  895. spepol:=polx
  896. end {spepol};
  897. function spepow(a, b: ArbFloat): ArbFloat;
  898. function PowInt(a: double; n: longint): double;
  899. var a1 : double;
  900. begin
  901. if n=0 then PowInt := 1 else
  902. begin
  903. a1 := 1;
  904. if n<0 then begin a := 1/a; n := -n end;
  905. while n>0
  906. do if Odd(n)
  907. then begin Dec(n); a1 := a1*a end
  908. else begin n := n div 2; a := sqr(a) end;
  909. PowInt := a1
  910. end
  911. end;
  912. var tb : longint;
  913. fb : double;
  914. begin
  915. { (a < 0, b niet geheel) of (a = 0, b <= 0), dan afbreken}
  916. if (a=0) then if (b<=0) then RunError(400) else begin SpePow :=0; exit end;
  917. tb := Trunc(b); fb := b-tb;
  918. if (a<0) and (fb<>0) then RunError(400);
  919. if a>0
  920. then if fb=0 then SpePow := PowInt(a, tb)
  921. else SpePow := PowInt(a, tb)*exp(fb*ln(a))
  922. else if odd(tb) then Spepow := -PowInt(-a, tb)
  923. else SpePow := PowInt(-a, tb)
  924. end; {spepow}
  925. function spesgn(x: ArbFloat): ArbInt;
  926. begin
  927. if x<0
  928. then
  929. spesgn:=-1
  930. else
  931. if x=0
  932. then
  933. spesgn:=0
  934. else
  935. spesgn:=1
  936. end; {spesgn}
  937. function spears(x: ArbFloat): ArbFloat;
  938. const
  939. pi2 = 1.570796326794897;
  940. a : array[0..17] of ArbFloat =
  941. ( 1.047197551196598e+0, 5.375149359132719e-2, 7.798902238957732e-3,
  942. 1.519668539582420e-3, 3.408637238430600e-4, 8.302317819598986e-5,
  943. 2.134554822576075e-5, 5.701781046148566e-6, 1.566985123962741e-6,
  944. 4.402076871418002e-7, 1.257811162594110e-7, 3.646577948300129e-8,
  945. 1.081021746966715e-8, 3.212744286269388e-9, 8.515014302985799e-10,
  946. 2.513296398553196e-10, 1.342121568282535e-10, 4.210346761190271e-11);
  947. var y, u, t, s : ArbFloat;
  948. uprang : boolean;
  949. begin
  950. if abs(x) > 1
  951. then
  952. RunError(401);
  953. u:=sqr(x); uprang:= u > 0.5;
  954. if uprang
  955. then
  956. u:=1-u;
  957. t:=4*u-1; y:=spepol(t, a[0], sizeof(a) div sizeof(ArbFloat) - 1);
  958. if uprang
  959. then
  960. begin
  961. s:=pi2-sqrt(u)*y;
  962. if x < 0
  963. then
  964. s:=-s;
  965. spears:=s
  966. end
  967. else
  968. spears:=x*y
  969. end; {spears}
  970. function spearc(x: ArbFloat): ArbFloat;
  971. const
  972. pi2 = 1.570796326794897;
  973. a : array[0..17] of ArbFloat =
  974. ( 1.047197551196598e+0, 5.375149359132719e-2, 7.798902238957732e-3,
  975. 1.519668539582420e-3, 3.408637238430600e-4, 8.302317819598986e-5,
  976. 2.134554822576075e-5, 5.701781046148566e-6, 1.566985123962741e-6,
  977. 4.402076871418002e-7, 1.257811162594110e-7, 3.646577948300129e-8,
  978. 1.081021746966715e-8, 3.212744286269388e-9, 8.515014302985799e-10,
  979. 2.513296398553196e-10, 1.342121568282535e-10, 4.210346761190271e-11);
  980. var u, t, y, s : ArbFloat;
  981. uprang : boolean;
  982. begin
  983. if abs(x)>1.0
  984. then
  985. RunError(402);
  986. u:=sqr(x); uprang:=u>0.5;
  987. if uprang
  988. then
  989. u:=1-u;
  990. t:=4*u-1; y:=spepol(t, a[0], sizeof(a) div sizeof(ArbFloat) - 1);
  991. if uprang
  992. then
  993. begin
  994. s:=sqrt(u)*y;
  995. if x<0
  996. then
  997. s:=2*pi2-s;
  998. spearc:=s
  999. end
  1000. else
  1001. spearc:=pi2-x*y
  1002. end; {spearc}
  1003. function spesih(x: ArbFloat): ArbFloat;
  1004. const
  1005. a : array[0..6] of ArbFloat =
  1006. ( 1.085441641272607e+0, 8.757509762437522e-2, 2.158779361257021e-3,
  1007. 2.549839945498292e-5, 1.761854853281383e-7, 7.980704288665359e-10,
  1008. 2.551377137317034e-12);
  1009. var u : ArbFloat;
  1010. begin
  1011. if abs(x)<=1.0
  1012. then
  1013. begin
  1014. u:=2*sqr(x)-1;
  1015. spesih:=x*spepol(u, a[0], sizeof(a) div sizeof(ArbFloat) - 1)
  1016. end
  1017. else
  1018. begin
  1019. u:=exp(x); spesih:=(u-1/u)/2
  1020. end
  1021. end; {spesih}
  1022. function specoh(x: ArbFloat): ArbFloat;
  1023. var u: ArbFloat;
  1024. begin
  1025. u:=exp(x); specoh:=(u+1/u)/2
  1026. end; {specoh}
  1027. function spetah(x: ArbFloat): ArbFloat;
  1028. const
  1029. xhi = 18.50;
  1030. a : array[0..15] of ArbFloat =
  1031. ( 8.610571715805476e-1, -1.158834489728470e-1, 1.918072383973950e-2,
  1032. -3.225255180728459e-3, 5.433071386922689e-4, -9.154289983175165e-5,
  1033. 1.542469328074432e-5, -2.599022539340038e-6, 4.379282308765732e-7,
  1034. -7.378980192173815e-8, 1.243517352745986e-8, -2.095373768837420e-9,
  1035. 3.509758916273561e-10,-5.908745181531817e-11, 1.124199312776748e-11,
  1036. -1.907888434471600e-12);
  1037. var t, y: ArbFloat;
  1038. begin
  1039. t:=abs(x);
  1040. if t <= 1
  1041. then
  1042. begin
  1043. y:=2*sqr(x)-1;
  1044. spetah:=x*spepol(y, a[0], sizeof(a) div sizeof(ArbFloat) - 1)
  1045. end
  1046. else
  1047. if t < xhi
  1048. then
  1049. begin
  1050. y:=exp(2*x); spetah:=(y-1)/(y+1)
  1051. end
  1052. else
  1053. spetah:=spesgn(x)
  1054. end; {spetah}
  1055. function speash(x: ArbFloat): ArbFloat;
  1056. const
  1057. xhi = 1e9;
  1058. c : array[0..18] of ArbFloat =
  1059. ( 9.312298594527122e-1, -5.736663926249348e-2,
  1060. 9.004288574881897e-3, -1.833458667045431e-3,
  1061. 4.230023450529706e-4, -1.050715136470630e-4,
  1062. 2.740790473603819e-5, -7.402952157663977e-6,
  1063. 2.052474396638805e-6, -5.807433412373489e-7,
  1064. 1.670117348345774e-7, -4.863477336087045e-8,
  1065. 1.432753532351304e-8, -4.319978113584910e-9,
  1066. 1.299779213740398e-9, -3.394726871170490e-10,
  1067. 1.008344962167889e-10, -5.731943029121004e-11,
  1068. 1.810792296549804e-11);
  1069. var t : ArbFloat;
  1070. begin
  1071. t:=abs(x);
  1072. if t <= 1 then
  1073. speash:=x*spepol(2*sqr(x)-1, c[0], sizeof(c) div sizeof(ArbFloat) - 1)
  1074. else
  1075. if t < xhi then
  1076. speash:=ln(sqrt(sqr(x)+1)+t)*spesgn(x)
  1077. else
  1078. speash:=ln(2*t)*spesgn(x)
  1079. end; {speash}
  1080. function speach(x: ArbFloat): ArbFloat;
  1081. const
  1082. xhi = 1e9;
  1083. begin
  1084. if x<1 then
  1085. RunError(405);
  1086. if x=1 then
  1087. speach:=0
  1088. else
  1089. if x<=xhi then
  1090. speach:=ln(x+sqrt(sqr(x)-1))
  1091. else
  1092. speach:=ln(2*x)
  1093. end; {speach}
  1094. function speath(x: ArbFloat): ArbFloat;
  1095. const
  1096. c : array[0..19] of ArbFloat =
  1097. ( 1.098612288668110e+0, 1.173605223326117e-1, 2.309071936165689e-2,
  1098. 5.449091889986991e-3, 1.404884102286929e-3, 3.816948426588058e-4,
  1099. 1.073604335435426e-4, 3.095027782918129e-5, 9.088050814470148e-6,
  1100. 2.706881064641104e-6, 8.155200644023077e-7, 2.479830612463254e-7,
  1101. 7.588067811453948e-8, 2.339295963220429e-8, 7.408486568719348e-9,
  1102. 2.319454882064018e-9, 5.960921368486746e-10, 1.820410351379402e-10,
  1103. 1.184977617320312e-10, 3.856235316559190e-11);
  1104. var t, u: ArbFloat;
  1105. begin
  1106. t:=abs(x);
  1107. if t >= 1 then
  1108. RunError(406);
  1109. u:=sqr(x);
  1110. if u < 0.5 then
  1111. speath:=x*spepol(4*u-1, c[0], sizeof(c) div sizeof(ArbFloat) - 1)
  1112. else { 0.5 < x*x < 1 }
  1113. speath:=ln((1+t)/(1-t))/2*spesgn(x)
  1114. end; {speath}
  1115. var exitsave : pointer;
  1116. procedure MyExit; Far;
  1117. const ErrorS : array[400..408,1..6] of char =
  1118. ('spepow',
  1119. 'spebk0',
  1120. 'spebk1',
  1121. 'speby0',
  1122. 'speby1',
  1123. 'speach',
  1124. 'speath',
  1125. 'spegam',
  1126. 'spelga');
  1127. var ErrFil : text;
  1128. begin
  1129. ExitProc := ExitSave;
  1130. Assign(ErrFil, 'CON');
  1131. ReWrite(ErrFil);
  1132. if (ExitCode>=400) AND (ExitCode<=408) then
  1133. begin
  1134. write(ErrFil, 'critical error in ', ErrorS[ExitCode]);
  1135. ExitCode := 201
  1136. end;
  1137. Close(ErrFil)
  1138. end;
  1139. begin
  1140. ExitSave := ExitProc;
  1141. ExitProc := @MyExit;
  1142. end.