gsl_specfunc__airy.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /* specfunc/airy.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_sf_trig.h"
  24. #include "gsl_sf_airy.h"
  25. #include "gsl_specfunc__error.h"
  26. #include "gsl_specfunc__check.h"
  27. #include "gsl_specfunc__chebyshev.h"
  28. #include "gsl_specfunc__cheb_eval_mode.c"
  29. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  30. /* chebyshev expansions for Airy modulus and phase
  31. based on SLATEC r9aimp()
  32. Series for AM21 on the interval -1.25000D-01 to 0.
  33. with weighted error 2.89E-17
  34. log weighted error 16.54
  35. significant figures required 14.15
  36. decimal places required 17.34
  37. Series for ATH1 on the interval -1.25000D-01 to 0.
  38. with weighted error 2.53E-17
  39. log weighted error 16.60
  40. significant figures required 15.15
  41. decimal places required 17.38
  42. Series for AM22 on the interval -1.00000D+00 to -1.25000D-01
  43. with weighted error 2.99E-17
  44. log weighted error 16.52
  45. significant figures required 14.57
  46. decimal places required 17.28
  47. Series for ATH2 on the interval -1.00000D+00 to -1.25000D-01
  48. with weighted error 2.57E-17
  49. log weighted error 16.59
  50. significant figures required 15.07
  51. decimal places required 17.34
  52. */
  53. static double am21_data[37] = {
  54. 0.0065809191761485,
  55. 0.0023675984685722,
  56. 0.0001324741670371,
  57. 0.0000157600904043,
  58. 0.0000027529702663,
  59. 0.0000006102679017,
  60. 0.0000001595088468,
  61. 0.0000000471033947,
  62. 0.0000000152933871,
  63. 0.0000000053590722,
  64. 0.0000000020000910,
  65. 0.0000000007872292,
  66. 0.0000000003243103,
  67. 0.0000000001390106,
  68. 0.0000000000617011,
  69. 0.0000000000282491,
  70. 0.0000000000132979,
  71. 0.0000000000064188,
  72. 0.0000000000031697,
  73. 0.0000000000015981,
  74. 0.0000000000008213,
  75. 0.0000000000004296,
  76. 0.0000000000002284,
  77. 0.0000000000001232,
  78. 0.0000000000000675,
  79. 0.0000000000000374,
  80. 0.0000000000000210,
  81. 0.0000000000000119,
  82. 0.0000000000000068,
  83. 0.0000000000000039,
  84. 0.0000000000000023,
  85. 0.0000000000000013,
  86. 0.0000000000000008,
  87. 0.0000000000000005,
  88. 0.0000000000000003,
  89. 0.0000000000000001,
  90. 0.0000000000000001
  91. };
  92. static cheb_series am21_cs = {
  93. am21_data,
  94. 36,
  95. -1, 1,
  96. 20
  97. };
  98. static double ath1_data[36] = {
  99. -0.07125837815669365,
  100. -0.00590471979831451,
  101. -0.00012114544069499,
  102. -0.00000988608542270,
  103. -0.00000138084097352,
  104. -0.00000026142640172,
  105. -0.00000006050432589,
  106. -0.00000001618436223,
  107. -0.00000000483464911,
  108. -0.00000000157655272,
  109. -0.00000000055231518,
  110. -0.00000000020545441,
  111. -0.00000000008043412,
  112. -0.00000000003291252,
  113. -0.00000000001399875,
  114. -0.00000000000616151,
  115. -0.00000000000279614,
  116. -0.00000000000130428,
  117. -0.00000000000062373,
  118. -0.00000000000030512,
  119. -0.00000000000015239,
  120. -0.00000000000007758,
  121. -0.00000000000004020,
  122. -0.00000000000002117,
  123. -0.00000000000001132,
  124. -0.00000000000000614,
  125. -0.00000000000000337,
  126. -0.00000000000000188,
  127. -0.00000000000000105,
  128. -0.00000000000000060,
  129. -0.00000000000000034,
  130. -0.00000000000000020,
  131. -0.00000000000000011,
  132. -0.00000000000000007,
  133. -0.00000000000000004,
  134. -0.00000000000000002
  135. };
  136. static cheb_series ath1_cs = {
  137. ath1_data,
  138. 35,
  139. -1, 1,
  140. 15
  141. };
  142. static double am22_data[33] = {
  143. -0.01562844480625341,
  144. 0.00778336445239681,
  145. 0.00086705777047718,
  146. 0.00015696627315611,
  147. 0.00003563962571432,
  148. 0.00000924598335425,
  149. 0.00000262110161850,
  150. 0.00000079188221651,
  151. 0.00000025104152792,
  152. 0.00000008265223206,
  153. 0.00000002805711662,
  154. 0.00000000976821090,
  155. 0.00000000347407923,
  156. 0.00000000125828132,
  157. 0.00000000046298826,
  158. 0.00000000017272825,
  159. 0.00000000006523192,
  160. 0.00000000002490471,
  161. 0.00000000000960156,
  162. 0.00000000000373448,
  163. 0.00000000000146417,
  164. 0.00000000000057826,
  165. 0.00000000000022991,
  166. 0.00000000000009197,
  167. 0.00000000000003700,
  168. 0.00000000000001496,
  169. 0.00000000000000608,
  170. 0.00000000000000248,
  171. 0.00000000000000101,
  172. 0.00000000000000041,
  173. 0.00000000000000017,
  174. 0.00000000000000007,
  175. 0.00000000000000002
  176. };
  177. static cheb_series am22_cs = {
  178. am22_data,
  179. 32,
  180. -1, 1,
  181. 15
  182. };
  183. static double ath2_data[32] = {
  184. 0.00440527345871877,
  185. -0.03042919452318455,
  186. -0.00138565328377179,
  187. -0.00018044439089549,
  188. -0.00003380847108327,
  189. -0.00000767818353522,
  190. -0.00000196783944371,
  191. -0.00000054837271158,
  192. -0.00000016254615505,
  193. -0.00000005053049981,
  194. -0.00000001631580701,
  195. -0.00000000543420411,
  196. -0.00000000185739855,
  197. -0.00000000064895120,
  198. -0.00000000023105948,
  199. -0.00000000008363282,
  200. -0.00000000003071196,
  201. -0.00000000001142367,
  202. -0.00000000000429811,
  203. -0.00000000000163389,
  204. -0.00000000000062693,
  205. -0.00000000000024260,
  206. -0.00000000000009461,
  207. -0.00000000000003716,
  208. -0.00000000000001469,
  209. -0.00000000000000584,
  210. -0.00000000000000233,
  211. -0.00000000000000093,
  212. -0.00000000000000037,
  213. -0.00000000000000015,
  214. -0.00000000000000006,
  215. -0.00000000000000002
  216. };
  217. static cheb_series ath2_cs = {
  218. ath2_data,
  219. 31,
  220. -1, 1,
  221. 16
  222. };
  223. /* Airy modulus and phase for x < -1 */
  224. static
  225. int
  226. airy_mod_phase(const double x, gsl_mode_t mode, gsl_sf_result * mod, gsl_sf_result * phase)
  227. {
  228. gsl_sf_result result_m;
  229. gsl_sf_result result_p;
  230. double m, p;
  231. double sqx;
  232. if(x < -2.0) {
  233. double z = 16.0/(x*x*x) + 1.0;
  234. cheb_eval_mode_e(&am21_cs, z, mode, &result_m);
  235. cheb_eval_mode_e(&ath1_cs, z, mode, &result_p);
  236. }
  237. else if(x <= -1.0) {
  238. double z = (16.0/(x*x*x) + 9.0)/7.0;
  239. cheb_eval_mode_e(&am22_cs, z, mode, &result_m);
  240. cheb_eval_mode_e(&ath2_cs, z, mode, &result_p);
  241. }
  242. else {
  243. mod->val = 0.0;
  244. mod->err = 0.0;
  245. phase->val = 0.0;
  246. phase->err = 0.0;
  247. GSL_ERROR ("x is greater than 1.0", GSL_EDOM);
  248. }
  249. m = 0.3125 + result_m.val;
  250. p = -0.625 + result_p.val;
  251. sqx = sqrt(-x);
  252. mod->val = sqrt(m/sqx);
  253. mod->err = fabs(mod->val) * (GSL_DBL_EPSILON + fabs(result_m.err/result_m.val));
  254. phase->val = M_PI_4 - x*sqx * p;
  255. phase->err = fabs(phase->val) * (GSL_DBL_EPSILON + fabs(result_p.err/result_p.val));
  256. return GSL_SUCCESS;
  257. }
  258. /* Chebyshev series for Ai(x) with x in [-1,1]
  259. based on SLATEC ai(x)
  260. series for aif on the interval -1.00000d+00 to 1.00000d+00
  261. with weighted error 1.09e-19
  262. log weighted error 18.96
  263. significant figures required 17.76
  264. decimal places required 19.44
  265. series for aig on the interval -1.00000d+00 to 1.00000d+00
  266. with weighted error 1.51e-17
  267. log weighted error 16.82
  268. significant figures required 15.19
  269. decimal places required 17.27
  270. */
  271. static double ai_data_f[9] = {
  272. -0.03797135849666999750,
  273. 0.05919188853726363857,
  274. 0.00098629280577279975,
  275. 0.00000684884381907656,
  276. 0.00000002594202596219,
  277. 0.00000000006176612774,
  278. 0.00000000000010092454,
  279. 0.00000000000000012014,
  280. 0.00000000000000000010
  281. };
  282. static cheb_series aif_cs = {
  283. ai_data_f,
  284. 8,
  285. -1, 1,
  286. 8
  287. };
  288. static double ai_data_g[8] = {
  289. 0.01815236558116127,
  290. 0.02157256316601076,
  291. 0.00025678356987483,
  292. 0.00000142652141197,
  293. 0.00000000457211492,
  294. 0.00000000000952517,
  295. 0.00000000000001392,
  296. 0.00000000000000001
  297. };
  298. static cheb_series aig_cs = {
  299. ai_data_g,
  300. 7,
  301. -1, 1,
  302. 7
  303. };
  304. /* Chebvyshev series for Bi(x) with x in [-1,1]
  305. based on SLATEC bi(x)
  306. series for bif on the interval -1.00000d+00 to 1.00000d+00
  307. with weighted error 1.88e-19
  308. log weighted error 18.72
  309. significant figures required 17.74
  310. decimal places required 19.20
  311. series for big on the interval -1.00000d+00 to 1.00000d+00
  312. with weighted error 2.61e-17
  313. log weighted error 16.58
  314. significant figures required 15.17
  315. decimal places required 17.03
  316. */
  317. static double data_bif[9] = {
  318. -0.01673021647198664948,
  319. 0.10252335834249445610,
  320. 0.00170830925073815165,
  321. 0.00001186254546774468,
  322. 0.00000004493290701779,
  323. 0.00000000010698207143,
  324. 0.00000000000017480643,
  325. 0.00000000000000020810,
  326. 0.00000000000000000018
  327. };
  328. static cheb_series bif_cs = {
  329. data_bif,
  330. 8,
  331. -1, 1,
  332. 8
  333. };
  334. static double data_big[8] = {
  335. 0.02246622324857452,
  336. 0.03736477545301955,
  337. 0.00044476218957212,
  338. 0.00000247080756363,
  339. 0.00000000791913533,
  340. 0.00000000001649807,
  341. 0.00000000000002411,
  342. 0.00000000000000002
  343. };
  344. static cheb_series big_cs = {
  345. data_big,
  346. 7,
  347. -1, 1,
  348. 7
  349. };
  350. /* Chebyshev series for Bi(x) with x in [1,8]
  351. based on SLATEC bi(x)
  352. */
  353. static double data_bif2[10] = {
  354. 0.0998457269381604100,
  355. 0.4786249778630055380,
  356. 0.0251552119604330118,
  357. 0.0005820693885232645,
  358. 0.0000074997659644377,
  359. 0.0000000613460287034,
  360. 0.0000000003462753885,
  361. 0.0000000000014288910,
  362. 0.0000000000000044962,
  363. 0.0000000000000000111
  364. };
  365. static cheb_series bif2_cs = {
  366. data_bif2,
  367. 9,
  368. -1, 1,
  369. 9
  370. };
  371. static double data_big2[10] = {
  372. 0.033305662145514340,
  373. 0.161309215123197068,
  374. 0.0063190073096134286,
  375. 0.0001187904568162517,
  376. 0.0000013045345886200,
  377. 0.0000000093741259955,
  378. 0.0000000000474580188,
  379. 0.0000000000001783107,
  380. 0.0000000000000005167,
  381. 0.0000000000000000011
  382. };
  383. static cheb_series big2_cs = {
  384. data_big2,
  385. 9,
  386. -1, 1,
  387. 9
  388. };
  389. /* chebyshev for Ai(x) asymptotic factor
  390. based on SLATEC aie()
  391. Series for AIP on the interval 0. to 1.00000D+00
  392. with weighted error 5.10E-17
  393. log weighted error 16.29
  394. significant figures required 14.41
  395. decimal places required 17.06
  396. [GJ] Sun Apr 19 18:14:31 EDT 1998
  397. There was something wrong with these coefficients. I was getting
  398. errors after 3 or 4 digits. So I recomputed this table. Now I get
  399. double precision agreement with Mathematica. But it does not seem
  400. possible that the small differences here would account for the
  401. original discrepancy. There must have been something wrong with my
  402. original usage...
  403. */
  404. static double data_aip[36] = {
  405. -0.0187519297793867540198,
  406. -0.0091443848250055004725,
  407. 0.0009010457337825074652,
  408. -0.0001394184127221491507,
  409. 0.0000273815815785209370,
  410. -0.0000062750421119959424,
  411. 0.0000016064844184831521,
  412. -0.0000004476392158510354,
  413. 0.0000001334635874651668,
  414. -0.0000000420735334263215,
  415. 0.0000000139021990246364,
  416. -0.0000000047831848068048,
  417. 0.0000000017047897907465,
  418. -0.0000000006268389576018,
  419. 0.0000000002369824276612,
  420. -0.0000000000918641139267,
  421. 0.0000000000364278543037,
  422. -0.0000000000147475551725,
  423. 0.0000000000060851006556,
  424. -0.0000000000025552772234,
  425. 0.0000000000010906187250,
  426. -0.0000000000004725870319,
  427. 0.0000000000002076969064,
  428. -0.0000000000000924976214,
  429. 0.0000000000000417096723,
  430. -0.0000000000000190299093,
  431. 0.0000000000000087790676,
  432. -0.0000000000000040927557,
  433. 0.0000000000000019271068,
  434. -0.0000000000000009160199,
  435. 0.0000000000000004393567,
  436. -0.0000000000000002125503,
  437. 0.0000000000000001036735,
  438. -0.0000000000000000509642,
  439. 0.0000000000000000252377,
  440. -0.0000000000000000125793
  441. /*
  442. -.0187519297793868
  443. -.0091443848250055,
  444. .0009010457337825,
  445. -.0001394184127221,
  446. .0000273815815785,
  447. -.0000062750421119,
  448. .0000016064844184,
  449. -.0000004476392158,
  450. .0000001334635874,
  451. -.0000000420735334,
  452. .0000000139021990,
  453. -.0000000047831848,
  454. .0000000017047897,
  455. -.0000000006268389,
  456. .0000000002369824,
  457. -.0000000000918641,
  458. .0000000000364278,
  459. -.0000000000147475,
  460. .0000000000060851,
  461. -.0000000000025552,
  462. .0000000000010906,
  463. -.0000000000004725,
  464. .0000000000002076,
  465. -.0000000000000924,
  466. .0000000000000417,
  467. -.0000000000000190,
  468. .0000000000000087,
  469. -.0000000000000040,
  470. .0000000000000019,
  471. -.0000000000000009,
  472. .0000000000000004,
  473. -.0000000000000002,
  474. .0000000000000001,
  475. -.0000000000000000
  476. */
  477. };
  478. static cheb_series aip_cs = {
  479. data_aip,
  480. 35,
  481. -1, 1,
  482. 17
  483. };
  484. /* chebyshev for Bi(x) asymptotic factor
  485. based on SLATEC bie()
  486. Series for BIP on the interval 1.25000D-01 to 3.53553D-01
  487. with weighted error 1.91E-17
  488. log weighted error 16.72
  489. significant figures required 15.35
  490. decimal places required 17.41
  491. Series for BIP2 on the interval 0. to 1.25000D-01
  492. with weighted error 1.05E-18
  493. log weighted error 17.98
  494. significant figures required 16.74
  495. decimal places required 18.71
  496. */
  497. static double data_bip[24] = {
  498. -0.08322047477943447,
  499. 0.01146118927371174,
  500. 0.00042896440718911,
  501. -0.00014906639379950,
  502. -0.00001307659726787,
  503. 0.00000632759839610,
  504. -0.00000042226696982,
  505. -0.00000019147186298,
  506. 0.00000006453106284,
  507. -0.00000000784485467,
  508. -0.00000000096077216,
  509. 0.00000000070004713,
  510. -0.00000000017731789,
  511. 0.00000000002272089,
  512. 0.00000000000165404,
  513. -0.00000000000185171,
  514. 0.00000000000059576,
  515. -0.00000000000012194,
  516. 0.00000000000001334,
  517. 0.00000000000000172,
  518. -0.00000000000000145,
  519. 0.00000000000000049,
  520. -0.00000000000000011,
  521. 0.00000000000000001
  522. };
  523. static cheb_series bip_cs = {
  524. data_bip,
  525. 23,
  526. -1, 1,
  527. 14
  528. };
  529. static double data_bip2[29] = {
  530. -0.113596737585988679,
  531. 0.0041381473947881595,
  532. 0.0001353470622119332,
  533. 0.0000104273166530153,
  534. 0.0000013474954767849,
  535. 0.0000001696537405438,
  536. -0.0000000100965008656,
  537. -0.0000000167291194937,
  538. -0.0000000045815364485,
  539. 0.0000000003736681366,
  540. 0.0000000005766930320,
  541. 0.0000000000621812650,
  542. -0.0000000000632941202,
  543. -0.0000000000149150479,
  544. 0.0000000000078896213,
  545. 0.0000000000024960513,
  546. -0.0000000000012130075,
  547. -0.0000000000003740493,
  548. 0.0000000000002237727,
  549. 0.0000000000000474902,
  550. -0.0000000000000452616,
  551. -0.0000000000000030172,
  552. 0.0000000000000091058,
  553. -0.0000000000000009814,
  554. -0.0000000000000016429,
  555. 0.0000000000000005533,
  556. 0.0000000000000002175,
  557. -0.0000000000000001737,
  558. -0.0000000000000000010
  559. };
  560. static cheb_series bip2_cs = {
  561. data_bip2,
  562. 28,
  563. -1, 1,
  564. 10
  565. };
  566. /* assumes x >= 1.0 */
  567. inline static int
  568. airy_aie(const double x, gsl_mode_t mode, gsl_sf_result * result)
  569. {
  570. double sqx = sqrt(x);
  571. double z = 2.0/(x*sqx) - 1.0;
  572. double y = sqrt(sqx);
  573. gsl_sf_result result_c;
  574. cheb_eval_mode_e(&aip_cs, z, mode, &result_c);
  575. result->val = (0.28125 + result_c.val)/y;
  576. result->err = result_c.err/y + GSL_DBL_EPSILON * fabs(result->val);
  577. return GSL_SUCCESS;
  578. }
  579. /* assumes x >= 2.0 */
  580. static int airy_bie(const double x, gsl_mode_t mode, gsl_sf_result * result)
  581. {
  582. const double ATR = 8.7506905708484345;
  583. const double BTR = -2.0938363213560543;
  584. if(x < 4.0) {
  585. double sqx = sqrt(x);
  586. double z = ATR/(x*sqx) + BTR;
  587. double y = sqrt(sqx);
  588. gsl_sf_result result_c;
  589. cheb_eval_mode_e(&bip_cs, z, mode, &result_c);
  590. result->val = (0.625 + result_c.val)/y;
  591. result->err = result_c.err/y + GSL_DBL_EPSILON * fabs(result->val);
  592. }
  593. else {
  594. double sqx = sqrt(x);
  595. double z = 16.0/(x*sqx) - 1.0;
  596. double y = sqrt(sqx);
  597. gsl_sf_result result_c;
  598. cheb_eval_mode_e(&bip2_cs, z, mode, &result_c);
  599. result->val = (0.625 + result_c.val)/y;
  600. result->err = result_c.err/y + GSL_DBL_EPSILON * fabs(result->val);
  601. }
  602. return GSL_SUCCESS;
  603. }
  604. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  605. int
  606. gsl_sf_airy_Ai_e(const double x, const gsl_mode_t mode, gsl_sf_result * result)
  607. {
  608. /* CHECK_POINTER(result) */
  609. if(x < -1.0) {
  610. gsl_sf_result mod;
  611. gsl_sf_result theta;
  612. gsl_sf_result cos_result;
  613. int stat_mp = airy_mod_phase(x, mode, &mod, &theta);
  614. int stat_cos = gsl_sf_cos_err_e(theta.val, theta.err, &cos_result);
  615. result->val = mod.val * cos_result.val;
  616. result->err = fabs(mod.val * cos_result.err) + fabs(cos_result.val * mod.err);
  617. result->err += GSL_DBL_EPSILON * fabs(result->val);
  618. return GSL_ERROR_SELECT_2(stat_mp, stat_cos);
  619. }
  620. else if(x <= 1.0) {
  621. const double z = x*x*x;
  622. gsl_sf_result result_c0;
  623. gsl_sf_result result_c1;
  624. cheb_eval_mode_e(&aif_cs, z, mode, &result_c0);
  625. cheb_eval_mode_e(&aig_cs, z, mode, &result_c1);
  626. result->val = 0.375 + (result_c0.val - x*(0.25 + result_c1.val));
  627. result->err = result_c0.err + fabs(x*result_c1.err);
  628. result->err += GSL_DBL_EPSILON * fabs(result->val);
  629. return GSL_SUCCESS;
  630. }
  631. else {
  632. double x32 = x * sqrt(x);
  633. double s = exp(-2.0*x32/3.0);
  634. gsl_sf_result result_aie;
  635. int stat_aie = airy_aie(x, mode, &result_aie);
  636. result->val = result_aie.val * s;
  637. result->err = result_aie.err * s + result->val * x32 * GSL_DBL_EPSILON;
  638. result->err += GSL_DBL_EPSILON * fabs(result->val);
  639. CHECK_UNDERFLOW(result);
  640. return stat_aie;
  641. }
  642. }
  643. int
  644. gsl_sf_airy_Ai_scaled_e(const double x, gsl_mode_t mode, gsl_sf_result * result)
  645. {
  646. /* CHECK_POINTER(result) */
  647. if(x < -1.0) {
  648. gsl_sf_result mod;
  649. gsl_sf_result theta;
  650. gsl_sf_result cos_result;
  651. int stat_mp = airy_mod_phase(x, mode, &mod, &theta);
  652. int stat_cos = gsl_sf_cos_err_e(theta.val, theta.err, &cos_result);
  653. result->val = mod.val * cos_result.val;
  654. result->err = fabs(mod.val * cos_result.err) + fabs(cos_result.val * mod.err);
  655. result->err += GSL_DBL_EPSILON * fabs(result->val);
  656. return GSL_ERROR_SELECT_2(stat_mp, stat_cos);
  657. }
  658. else if(x <= 1.0) {
  659. const double z = x*x*x;
  660. gsl_sf_result result_c0;
  661. gsl_sf_result result_c1;
  662. cheb_eval_mode_e(&aif_cs, z, mode, &result_c0);
  663. cheb_eval_mode_e(&aig_cs, z, mode, &result_c1);
  664. result->val = 0.375 + (result_c0.val - x*(0.25 + result_c1.val));
  665. result->err = result_c0.err + fabs(x*result_c1.err);
  666. result->err += GSL_DBL_EPSILON * fabs(result->val);
  667. if(x > 0.0) {
  668. const double scale = exp(2.0/3.0 * sqrt(z));
  669. result->val *= scale;
  670. result->err *= scale;
  671. }
  672. return GSL_SUCCESS;
  673. }
  674. else {
  675. return airy_aie(x, mode, result);
  676. }
  677. }
  678. int gsl_sf_airy_Bi_e(const double x, gsl_mode_t mode, gsl_sf_result * result)
  679. {
  680. /* CHECK_POINTER(result) */
  681. if(x < -1.0) {
  682. gsl_sf_result mod;
  683. gsl_sf_result theta;
  684. gsl_sf_result sin_result;
  685. int stat_mp = airy_mod_phase(x, mode, &mod, &theta);
  686. int stat_sin = gsl_sf_sin_err_e(theta.val, theta.err, &sin_result);
  687. result->val = mod.val * sin_result.val;
  688. result->err = fabs(mod.val * sin_result.err) + fabs(sin_result.val * mod.err);
  689. result->err += GSL_DBL_EPSILON * fabs(result->val);
  690. return GSL_ERROR_SELECT_2(stat_mp, stat_sin);
  691. }
  692. else if(x < 1.0) {
  693. const double z = x*x*x;
  694. gsl_sf_result result_c0;
  695. gsl_sf_result result_c1;
  696. cheb_eval_mode_e(&bif_cs, z, mode, &result_c0);
  697. cheb_eval_mode_e(&big_cs, z, mode, &result_c1);
  698. result->val = 0.625 + result_c0.val + x*(0.4375 + result_c1.val);
  699. result->err = result_c0.err + fabs(x * result_c1.err);
  700. result->err += GSL_DBL_EPSILON * fabs(result->val);
  701. return GSL_SUCCESS;
  702. }
  703. else if(x <= 2.0) {
  704. const double z = (2.0*x*x*x - 9.0)/7.0;
  705. gsl_sf_result result_c0;
  706. gsl_sf_result result_c1;
  707. cheb_eval_mode_e(&bif2_cs, z, mode, &result_c0);
  708. cheb_eval_mode_e(&big2_cs, z, mode, &result_c1);
  709. result->val = 1.125 + result_c0.val + x*(0.625 + result_c1.val);
  710. result->err = result_c0.err + fabs(x * result_c1.err);
  711. result->err += GSL_DBL_EPSILON * fabs(result->val);
  712. return GSL_SUCCESS;
  713. }
  714. else {
  715. const double y = 2.0*x*sqrt(x)/3.0;
  716. const double s = exp(y);
  717. if(y > GSL_LOG_DBL_MAX - 1.0) {
  718. OVERFLOW_ERROR(result);
  719. }
  720. else {
  721. gsl_sf_result result_bie;
  722. int stat_bie = airy_bie(x, mode, &result_bie);
  723. result->val = result_bie.val * s;
  724. result->err = result_bie.err * s + fabs(1.5*y * (GSL_DBL_EPSILON * result->val));
  725. result->err += GSL_DBL_EPSILON * fabs(result->val);
  726. return stat_bie;
  727. }
  728. }
  729. }
  730. int
  731. gsl_sf_airy_Bi_scaled_e(const double x, gsl_mode_t mode, gsl_sf_result * result)
  732. {
  733. /* CHECK_POINTER(result) */
  734. if(x < -1.0) {
  735. gsl_sf_result mod;
  736. gsl_sf_result theta;
  737. gsl_sf_result sin_result;
  738. int stat_mp = airy_mod_phase(x, mode, &mod, &theta);
  739. int stat_sin = gsl_sf_sin_err_e(theta.val, theta.err, &sin_result);
  740. result->val = mod.val * sin_result.val;
  741. result->err = fabs(mod.val * sin_result.err) + fabs(sin_result.val * mod.err);
  742. result->err += GSL_DBL_EPSILON * fabs(result->val);
  743. return GSL_ERROR_SELECT_2(stat_mp, stat_sin);
  744. }
  745. else if(x < 1.0) {
  746. const double z = x*x*x;
  747. gsl_sf_result result_c0;
  748. gsl_sf_result result_c1;
  749. cheb_eval_mode_e(&bif_cs, z, mode, &result_c0);
  750. cheb_eval_mode_e(&big_cs, z, mode, &result_c1);
  751. result->val = 0.625 + result_c0.val + x*(0.4375 + result_c1.val);
  752. result->err = result_c0.err + fabs(x * result_c1.err);
  753. result->err += GSL_DBL_EPSILON * fabs(result->val);
  754. if(x > 0.0) {
  755. const double scale = exp(-2.0/3.0 * sqrt(z));
  756. result->val *= scale;
  757. result->err *= scale;
  758. }
  759. return GSL_SUCCESS;
  760. }
  761. else if(x <= 2.0) {
  762. const double x3 = x*x*x;
  763. const double z = (2.0*x3 - 9.0)/7.0;
  764. const double s = exp(-2.0/3.0 * sqrt(x3));
  765. gsl_sf_result result_c0;
  766. gsl_sf_result result_c1;
  767. cheb_eval_mode_e(&bif2_cs, z, mode, &result_c0);
  768. cheb_eval_mode_e(&big2_cs, z, mode, &result_c1);
  769. result->val = s * (1.125 + result_c0.val + x*(0.625 + result_c1.val));
  770. result->err = s * (result_c0.err + fabs(x * result_c1.err));
  771. result->err += GSL_DBL_EPSILON * fabs(result->val);
  772. return GSL_SUCCESS;
  773. }
  774. else {
  775. return airy_bie(x, mode, result);
  776. }
  777. }
  778. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  779. #include "gsl_specfunc__eval.h"
  780. double gsl_sf_airy_Ai(const double x, gsl_mode_t mode)
  781. {
  782. EVAL_RESULT(gsl_sf_airy_Ai_e(x, mode, &result));
  783. }
  784. double gsl_sf_airy_Ai_scaled(const double x, gsl_mode_t mode)
  785. {
  786. EVAL_RESULT(gsl_sf_airy_Ai_scaled_e(x, mode, &result));
  787. }
  788. double gsl_sf_airy_Bi(const double x, gsl_mode_t mode)
  789. {
  790. EVAL_RESULT(gsl_sf_airy_Bi_e(x, mode, &result));
  791. }
  792. double gsl_sf_airy_Bi_scaled(const double x, gsl_mode_t mode)
  793. {
  794. EVAL_RESULT(gsl_sf_airy_Bi_scaled_e(x, mode, &result));
  795. }