spe.pas 39 KB

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