j0q.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. /* j0l.c
  2. *
  3. * Bessel function of order zero
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * long double x, y, j0l();
  10. *
  11. * y = j0l( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns Bessel function of first kind, order zero of the argument.
  18. *
  19. * The domain is divided into two major intervals [0, 2] and
  20. * (2, infinity). In the first interval the rational approximation
  21. * is J0(x) = 1 - x^2 / 4 + x^4 R(x^2)
  22. * The second interval is further partitioned into eight equal segments
  23. * of 1/x.
  24. *
  25. * J0(x) = sqrt(2/(pi x)) (P0(x) cos(X) - Q0(x) sin(X)),
  26. * X = x - pi/4,
  27. *
  28. * and the auxiliary functions are given by
  29. *
  30. * J0(x)cos(X) + Y0(x)sin(X) = sqrt( 2/(pi x)) P0(x),
  31. * P0(x) = 1 + 1/x^2 R(1/x^2)
  32. *
  33. * Y0(x)cos(X) - J0(x)sin(X) = sqrt( 2/(pi x)) Q0(x),
  34. * Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  35. *
  36. *
  37. *
  38. * ACCURACY:
  39. *
  40. * Absolute error:
  41. * arithmetic domain # trials peak rms
  42. * IEEE 0, 30 100000 1.7e-34 2.4e-35
  43. *
  44. *
  45. */
  46. /* y0l.c
  47. *
  48. * Bessel function of the second kind, order zero
  49. *
  50. *
  51. *
  52. * SYNOPSIS:
  53. *
  54. * double x, y, y0l();
  55. *
  56. * y = y0l( x );
  57. *
  58. *
  59. *
  60. * DESCRIPTION:
  61. *
  62. * Returns Bessel function of the second kind, of order
  63. * zero, of the argument.
  64. *
  65. * The approximation is the same as for J0(x), and
  66. * Y0(x) = sqrt(2/(pi x)) (P0(x) sin(X) + Q0(x) cos(X)).
  67. *
  68. * ACCURACY:
  69. *
  70. * Absolute error, when y0(x) < 1; else relative error:
  71. *
  72. * arithmetic domain # trials peak rms
  73. * IEEE 0, 30 100000 3.0e-34 2.7e-35
  74. *
  75. */
  76. /* Copyright 2001 by Stephen L. Moshier (moshier@na-net.ornl.gov).
  77. This library is free software; you can redistribute it and/or
  78. modify it under the terms of the GNU Lesser General Public
  79. License as published by the Free Software Foundation; either
  80. version 2.1 of the License, or (at your option) any later version.
  81. This library is distributed in the hope that it will be useful,
  82. but WITHOUT ANY WARRANTY; without even the implied warranty of
  83. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  84. Lesser General Public License for more details.
  85. You should have received a copy of the GNU Lesser General Public
  86. License along with this library; if not, see
  87. <http://www.gnu.org/licenses/>. */
  88. #include "quadmath-imp.h"
  89. /* 1 / sqrt(pi) */
  90. static const __float128 ONEOSQPI = 5.6418958354775628694807945156077258584405E-1Q;
  91. /* 2 / pi */
  92. static const __float128 TWOOPI = 6.3661977236758134307553505349005744813784E-1Q;
  93. static const __float128 zero = 0;
  94. /* J0(x) = 1 - x^2/4 + x^2 x^2 R(x^2)
  95. Peak relative error 3.4e-37
  96. 0 <= x <= 2 */
  97. #define NJ0_2N 6
  98. static const __float128 J0_2N[NJ0_2N + 1] = {
  99. 3.133239376997663645548490085151484674892E16Q,
  100. -5.479944965767990821079467311839107722107E14Q,
  101. 6.290828903904724265980249871997551894090E12Q,
  102. -3.633750176832769659849028554429106299915E10Q,
  103. 1.207743757532429576399485415069244807022E8Q,
  104. -2.107485999925074577174305650549367415465E5Q,
  105. 1.562826808020631846245296572935547005859E2Q,
  106. };
  107. #define NJ0_2D 6
  108. static const __float128 J0_2D[NJ0_2D + 1] = {
  109. 2.005273201278504733151033654496928968261E18Q,
  110. 2.063038558793221244373123294054149790864E16Q,
  111. 1.053350447931127971406896594022010524994E14Q,
  112. 3.496556557558702583143527876385508882310E11Q,
  113. 8.249114511878616075860654484367133976306E8Q,
  114. 1.402965782449571800199759247964242790589E6Q,
  115. 1.619910762853439600957801751815074787351E3Q,
  116. /* 1.000000000000000000000000000000000000000E0 */
  117. };
  118. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2),
  119. 0 <= 1/x <= .0625
  120. Peak relative error 3.3e-36 */
  121. #define NP16_IN 9
  122. static const __float128 P16_IN[NP16_IN + 1] = {
  123. -1.901689868258117463979611259731176301065E-16Q,
  124. -1.798743043824071514483008340803573980931E-13Q,
  125. -6.481746687115262291873324132944647438959E-11Q,
  126. -1.150651553745409037257197798528294248012E-8Q,
  127. -1.088408467297401082271185599507222695995E-6Q,
  128. -5.551996725183495852661022587879817546508E-5Q,
  129. -1.477286941214245433866838787454880214736E-3Q,
  130. -1.882877976157714592017345347609200402472E-2Q,
  131. -9.620983176855405325086530374317855880515E-2Q,
  132. -1.271468546258855781530458854476627766233E-1Q,
  133. };
  134. #define NP16_ID 9
  135. static const __float128 P16_ID[NP16_ID + 1] = {
  136. 2.704625590411544837659891569420764475007E-15Q,
  137. 2.562526347676857624104306349421985403573E-12Q,
  138. 9.259137589952741054108665570122085036246E-10Q,
  139. 1.651044705794378365237454962653430805272E-7Q,
  140. 1.573561544138733044977714063100859136660E-5Q,
  141. 8.134482112334882274688298469629884804056E-4Q,
  142. 2.219259239404080863919375103673593571689E-2Q,
  143. 2.976990606226596289580242451096393862792E-1Q,
  144. 1.713895630454693931742734911930937246254E0Q,
  145. 3.231552290717904041465898249160757368855E0Q,
  146. /* 1.000000000000000000000000000000000000000E0 */
  147. };
  148. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  149. 0.0625 <= 1/x <= 0.125
  150. Peak relative error 2.4e-35 */
  151. #define NP8_16N 10
  152. static const __float128 P8_16N[NP8_16N + 1] = {
  153. -2.335166846111159458466553806683579003632E-15Q,
  154. -1.382763674252402720401020004169367089975E-12Q,
  155. -3.192160804534716696058987967592784857907E-10Q,
  156. -3.744199606283752333686144670572632116899E-8Q,
  157. -2.439161236879511162078619292571922772224E-6Q,
  158. -9.068436986859420951664151060267045346549E-5Q,
  159. -1.905407090637058116299757292660002697359E-3Q,
  160. -2.164456143936718388053842376884252978872E-2Q,
  161. -1.212178415116411222341491717748696499966E-1Q,
  162. -2.782433626588541494473277445959593334494E-1Q,
  163. -1.670703190068873186016102289227646035035E-1Q,
  164. };
  165. #define NP8_16D 10
  166. static const __float128 P8_16D[NP8_16D + 1] = {
  167. 3.321126181135871232648331450082662856743E-14Q,
  168. 1.971894594837650840586859228510007703641E-11Q,
  169. 4.571144364787008285981633719513897281690E-9Q,
  170. 5.396419143536287457142904742849052402103E-7Q,
  171. 3.551548222385845912370226756036899901549E-5Q,
  172. 1.342353874566932014705609788054598013516E-3Q,
  173. 2.899133293006771317589357444614157734385E-2Q,
  174. 3.455374978185770197704507681491574261545E-1Q,
  175. 2.116616964297512311314454834712634820514E0Q,
  176. 5.850768316827915470087758636881584174432E0Q,
  177. 5.655273858938766830855753983631132928968E0Q,
  178. /* 1.000000000000000000000000000000000000000E0 */
  179. };
  180. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  181. 0.125 <= 1/x <= 0.1875
  182. Peak relative error 2.7e-35 */
  183. #define NP5_8N 10
  184. static const __float128 P5_8N[NP5_8N + 1] = {
  185. -1.270478335089770355749591358934012019596E-12Q,
  186. -4.007588712145412921057254992155810347245E-10Q,
  187. -4.815187822989597568124520080486652009281E-8Q,
  188. -2.867070063972764880024598300408284868021E-6Q,
  189. -9.218742195161302204046454768106063638006E-5Q,
  190. -1.635746821447052827526320629828043529997E-3Q,
  191. -1.570376886640308408247709616497261011707E-2Q,
  192. -7.656484795303305596941813361786219477807E-2Q,
  193. -1.659371030767513274944805479908858628053E-1Q,
  194. -1.185340550030955660015841796219919804915E-1Q,
  195. -8.920026499909994671248893388013790366712E-3Q,
  196. };
  197. #define NP5_8D 9
  198. static const __float128 P5_8D[NP5_8D + 1] = {
  199. 1.806902521016705225778045904631543990314E-11Q,
  200. 5.728502760243502431663549179135868966031E-9Q,
  201. 6.938168504826004255287618819550667978450E-7Q,
  202. 4.183769964807453250763325026573037785902E-5Q,
  203. 1.372660678476925468014882230851637878587E-3Q,
  204. 2.516452105242920335873286419212708961771E-2Q,
  205. 2.550502712902647803796267951846557316182E-1Q,
  206. 1.365861559418983216913629123778747617072E0Q,
  207. 3.523825618308783966723472468855042541407E0Q,
  208. 3.656365803506136165615111349150536282434E0Q,
  209. /* 1.000000000000000000000000000000000000000E0 */
  210. };
  211. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  212. Peak relative error 3.5e-35
  213. 0.1875 <= 1/x <= 0.25 */
  214. #define NP4_5N 9
  215. static const __float128 P4_5N[NP4_5N + 1] = {
  216. -9.791405771694098960254468859195175708252E-10Q,
  217. -1.917193059944531970421626610188102836352E-7Q,
  218. -1.393597539508855262243816152893982002084E-5Q,
  219. -4.881863490846771259880606911667479860077E-4Q,
  220. -8.946571245022470127331892085881699269853E-3Q,
  221. -8.707474232568097513415336886103899434251E-2Q,
  222. -4.362042697474650737898551272505525973766E-1Q,
  223. -1.032712171267523975431451359962375617386E0Q,
  224. -9.630502683169895107062182070514713702346E-1Q,
  225. -2.251804386252969656586810309252357233320E-1Q,
  226. };
  227. #define NP4_5D 9
  228. static const __float128 P4_5D[NP4_5D + 1] = {
  229. 1.392555487577717669739688337895791213139E-8Q,
  230. 2.748886559120659027172816051276451376854E-6Q,
  231. 2.024717710644378047477189849678576659290E-4Q,
  232. 7.244868609350416002930624752604670292469E-3Q,
  233. 1.373631762292244371102989739300382152416E-1Q,
  234. 1.412298581400224267910294815260613240668E0Q,
  235. 7.742495637843445079276397723849017617210E0Q,
  236. 2.138429269198406512028307045259503811861E1Q,
  237. 2.651547684548423476506826951831712762610E1Q,
  238. 1.167499382465291931571685222882909166935E1Q,
  239. /* 1.000000000000000000000000000000000000000E0 */
  240. };
  241. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  242. Peak relative error 2.3e-36
  243. 0.25 <= 1/x <= 0.3125 */
  244. #define NP3r2_4N 9
  245. static const __float128 P3r2_4N[NP3r2_4N + 1] = {
  246. -2.589155123706348361249809342508270121788E-8Q,
  247. -3.746254369796115441118148490849195516593E-6Q,
  248. -1.985595497390808544622893738135529701062E-4Q,
  249. -5.008253705202932091290132760394976551426E-3Q,
  250. -6.529469780539591572179155511840853077232E-2Q,
  251. -4.468736064761814602927408833818990271514E-1Q,
  252. -1.556391252586395038089729428444444823380E0Q,
  253. -2.533135309840530224072920725976994981638E0Q,
  254. -1.605509621731068453869408718565392869560E0Q,
  255. -2.518966692256192789269859830255724429375E-1Q,
  256. };
  257. #define NP3r2_4D 9
  258. static const __float128 P3r2_4D[NP3r2_4D + 1] = {
  259. 3.682353957237979993646169732962573930237E-7Q,
  260. 5.386741661883067824698973455566332102029E-5Q,
  261. 2.906881154171822780345134853794241037053E-3Q,
  262. 7.545832595801289519475806339863492074126E-2Q,
  263. 1.029405357245594877344360389469584526654E0Q,
  264. 7.565706120589873131187989560509757626725E0Q,
  265. 2.951172890699569545357692207898667665796E1Q,
  266. 5.785723537170311456298467310529815457536E1Q,
  267. 5.095621464598267889126015412522773474467E1Q,
  268. 1.602958484169953109437547474953308401442E1Q,
  269. /* 1.000000000000000000000000000000000000000E0 */
  270. };
  271. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  272. Peak relative error 1.0e-35
  273. 0.3125 <= 1/x <= 0.375 */
  274. #define NP2r7_3r2N 9
  275. static const __float128 P2r7_3r2N[NP2r7_3r2N + 1] = {
  276. -1.917322340814391131073820537027234322550E-7Q,
  277. -1.966595744473227183846019639723259011906E-5Q,
  278. -7.177081163619679403212623526632690465290E-4Q,
  279. -1.206467373860974695661544653741899755695E-2Q,
  280. -1.008656452188539812154551482286328107316E-1Q,
  281. -4.216016116408810856620947307438823892707E-1Q,
  282. -8.378631013025721741744285026537009814161E-1Q,
  283. -6.973895635309960850033762745957946272579E-1Q,
  284. -1.797864718878320770670740413285763554812E-1Q,
  285. -4.098025357743657347681137871388402849581E-3Q,
  286. };
  287. #define NP2r7_3r2D 8
  288. static const __float128 P2r7_3r2D[NP2r7_3r2D + 1] = {
  289. 2.726858489303036441686496086962545034018E-6Q,
  290. 2.840430827557109238386808968234848081424E-4Q,
  291. 1.063826772041781947891481054529454088832E-2Q,
  292. 1.864775537138364773178044431045514405468E-1Q,
  293. 1.665660052857205170440952607701728254211E0Q,
  294. 7.723745889544331153080842168958348568395E0Q,
  295. 1.810726427571829798856428548102077799835E1Q,
  296. 1.986460672157794440666187503833545388527E1Q,
  297. 8.645503204552282306364296517220055815488E0Q,
  298. /* 1.000000000000000000000000000000000000000E0 */
  299. };
  300. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  301. Peak relative error 1.3e-36
  302. 0.3125 <= 1/x <= 0.4375 */
  303. #define NP2r3_2r7N 9
  304. static const __float128 P2r3_2r7N[NP2r3_2r7N + 1] = {
  305. -1.594642785584856746358609622003310312622E-6Q,
  306. -1.323238196302221554194031733595194539794E-4Q,
  307. -3.856087818696874802689922536987100372345E-3Q,
  308. -5.113241710697777193011470733601522047399E-2Q,
  309. -3.334229537209911914449990372942022350558E-1Q,
  310. -1.075703518198127096179198549659283422832E0Q,
  311. -1.634174803414062725476343124267110981807E0Q,
  312. -1.030133247434119595616826842367268304880E0Q,
  313. -1.989811539080358501229347481000707289391E-1Q,
  314. -3.246859189246653459359775001466924610236E-3Q,
  315. };
  316. #define NP2r3_2r7D 8
  317. static const __float128 P2r3_2r7D[NP2r3_2r7D + 1] = {
  318. 2.267936634217251403663034189684284173018E-5Q,
  319. 1.918112982168673386858072491437971732237E-3Q,
  320. 5.771704085468423159125856786653868219522E-2Q,
  321. 8.056124451167969333717642810661498890507E-1Q,
  322. 5.687897967531010276788680634413789328776E0Q,
  323. 2.072596760717695491085444438270778394421E1Q,
  324. 3.801722099819929988585197088613160496684E1Q,
  325. 3.254620235902912339534998592085115836829E1Q,
  326. 1.104847772130720331801884344645060675036E1Q,
  327. /* 1.000000000000000000000000000000000000000E0 */
  328. };
  329. /* J0(x)cosX + Y0(x)sinX = sqrt( 2/(pi x)) P0(x), P0(x) = 1 + 1/x^2 R(1/x^2)
  330. Peak relative error 1.2e-35
  331. 0.4375 <= 1/x <= 0.5 */
  332. #define NP2_2r3N 8
  333. static const __float128 P2_2r3N[NP2_2r3N + 1] = {
  334. -1.001042324337684297465071506097365389123E-4Q,
  335. -6.289034524673365824853547252689991418981E-3Q,
  336. -1.346527918018624234373664526930736205806E-1Q,
  337. -1.268808313614288355444506172560463315102E0Q,
  338. -5.654126123607146048354132115649177406163E0Q,
  339. -1.186649511267312652171775803270911971693E1Q,
  340. -1.094032424931998612551588246779200724257E1Q,
  341. -3.728792136814520055025256353193674625267E0Q,
  342. -3.000348318524471807839934764596331810608E-1Q,
  343. };
  344. #define NP2_2r3D 8
  345. static const __float128 P2_2r3D[NP2_2r3D + 1] = {
  346. 1.423705538269770974803901422532055612980E-3Q,
  347. 9.171476630091439978533535167485230575894E-2Q,
  348. 2.049776318166637248868444600215942828537E0Q,
  349. 2.068970329743769804547326701946144899583E1Q,
  350. 1.025103500560831035592731539565060347709E2Q,
  351. 2.528088049697570728252145557167066708284E2Q,
  352. 2.992160327587558573740271294804830114205E2Q,
  353. 1.540193761146551025832707739468679973036E2Q,
  354. 2.779516701986912132637672140709452502650E1Q,
  355. /* 1.000000000000000000000000000000000000000E0 */
  356. };
  357. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  358. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  359. Peak relative error 2.2e-35
  360. 0 <= 1/x <= .0625 */
  361. #define NQ16_IN 10
  362. static const __float128 Q16_IN[NQ16_IN + 1] = {
  363. 2.343640834407975740545326632205999437469E-18Q,
  364. 2.667978112927811452221176781536278257448E-15Q,
  365. 1.178415018484555397390098879501969116536E-12Q,
  366. 2.622049767502719728905924701288614016597E-10Q,
  367. 3.196908059607618864801313380896308968673E-8Q,
  368. 2.179466154171673958770030655199434798494E-6Q,
  369. 8.139959091628545225221976413795645177291E-5Q,
  370. 1.563900725721039825236927137885747138654E-3Q,
  371. 1.355172364265825167113562519307194840307E-2Q,
  372. 3.928058355906967977269780046844768588532E-2Q,
  373. 1.107891967702173292405380993183694932208E-2Q,
  374. };
  375. #define NQ16_ID 9
  376. static const __float128 Q16_ID[NQ16_ID + 1] = {
  377. 3.199850952578356211091219295199301766718E-17Q,
  378. 3.652601488020654842194486058637953363918E-14Q,
  379. 1.620179741394865258354608590461839031281E-11Q,
  380. 3.629359209474609630056463248923684371426E-9Q,
  381. 4.473680923894354600193264347733477363305E-7Q,
  382. 3.106368086644715743265603656011050476736E-5Q,
  383. 1.198239259946770604954664925153424252622E-3Q,
  384. 2.446041004004283102372887804475767568272E-2Q,
  385. 2.403235525011860603014707768815113698768E-1Q,
  386. 9.491006790682158612266270665136910927149E-1Q,
  387. /* 1.000000000000000000000000000000000000000E0 */
  388. };
  389. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  390. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  391. Peak relative error 5.1e-36
  392. 0.0625 <= 1/x <= 0.125 */
  393. #define NQ8_16N 11
  394. static const __float128 Q8_16N[NQ8_16N + 1] = {
  395. 1.001954266485599464105669390693597125904E-17Q,
  396. 7.545499865295034556206475956620160007849E-15Q,
  397. 2.267838684785673931024792538193202559922E-12Q,
  398. 3.561909705814420373609574999542459912419E-10Q,
  399. 3.216201422768092505214730633842924944671E-8Q,
  400. 1.731194793857907454569364622452058554314E-6Q,
  401. 5.576944613034537050396518509871004586039E-5Q,
  402. 1.051787760316848982655967052985391418146E-3Q,
  403. 1.102852974036687441600678598019883746959E-2Q,
  404. 5.834647019292460494254225988766702933571E-2Q,
  405. 1.290281921604364618912425380717127576529E-1Q,
  406. 7.598886310387075708640370806458926458301E-2Q,
  407. };
  408. #define NQ8_16D 11
  409. static const __float128 Q8_16D[NQ8_16D + 1] = {
  410. 1.368001558508338469503329967729951830843E-16Q,
  411. 1.034454121857542147020549303317348297289E-13Q,
  412. 3.128109209247090744354764050629381674436E-11Q,
  413. 4.957795214328501986562102573522064468671E-9Q,
  414. 4.537872468606711261992676606899273588899E-7Q,
  415. 2.493639207101727713192687060517509774182E-5Q,
  416. 8.294957278145328349785532236663051405805E-4Q,
  417. 1.646471258966713577374948205279380115839E-2Q,
  418. 1.878910092770966718491814497982191447073E-1Q,
  419. 1.152641605706170353727903052525652504075E0Q,
  420. 3.383550240669773485412333679367792932235E0Q,
  421. 3.823875252882035706910024716609908473970E0Q,
  422. /* 1.000000000000000000000000000000000000000E0 */
  423. };
  424. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  425. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  426. Peak relative error 3.9e-35
  427. 0.125 <= 1/x <= 0.1875 */
  428. #define NQ5_8N 10
  429. static const __float128 Q5_8N[NQ5_8N + 1] = {
  430. 1.750399094021293722243426623211733898747E-13Q,
  431. 6.483426211748008735242909236490115050294E-11Q,
  432. 9.279430665656575457141747875716899958373E-9Q,
  433. 6.696634968526907231258534757736576340266E-7Q,
  434. 2.666560823798895649685231292142838188061E-5Q,
  435. 6.025087697259436271271562769707550594540E-4Q,
  436. 7.652807734168613251901945778921336353485E-3Q,
  437. 5.226269002589406461622551452343519078905E-2Q,
  438. 1.748390159751117658969324896330142895079E-1Q,
  439. 2.378188719097006494782174902213083589660E-1Q,
  440. 8.383984859679804095463699702165659216831E-2Q,
  441. };
  442. #define NQ5_8D 10
  443. static const __float128 Q5_8D[NQ5_8D + 1] = {
  444. 2.389878229704327939008104855942987615715E-12Q,
  445. 8.926142817142546018703814194987786425099E-10Q,
  446. 1.294065862406745901206588525833274399038E-7Q,
  447. 9.524139899457666250828752185212769682191E-6Q,
  448. 3.908332488377770886091936221573123353489E-4Q,
  449. 9.250427033957236609624199884089916836748E-3Q,
  450. 1.263420066165922645975830877751588421451E-1Q,
  451. 9.692527053860420229711317379861733180654E-1Q,
  452. 3.937813834630430172221329298841520707954E0Q,
  453. 7.603126427436356534498908111445191312181E0Q,
  454. 5.670677653334105479259958485084550934305E0Q,
  455. /* 1.000000000000000000000000000000000000000E0 */
  456. };
  457. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  458. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  459. Peak relative error 3.2e-35
  460. 0.1875 <= 1/x <= 0.25 */
  461. #define NQ4_5N 10
  462. static const __float128 Q4_5N[NQ4_5N + 1] = {
  463. 2.233870042925895644234072357400122854086E-11Q,
  464. 5.146223225761993222808463878999151699792E-9Q,
  465. 4.459114531468296461688753521109797474523E-7Q,
  466. 1.891397692931537975547242165291668056276E-5Q,
  467. 4.279519145911541776938964806470674565504E-4Q,
  468. 5.275239415656560634702073291768904783989E-3Q,
  469. 3.468698403240744801278238473898432608887E-2Q,
  470. 1.138773146337708415188856882915457888274E-1Q,
  471. 1.622717518946443013587108598334636458955E-1Q,
  472. 7.249040006390586123760992346453034628227E-2Q,
  473. 1.941595365256460232175236758506411486667E-3Q,
  474. };
  475. #define NQ4_5D 9
  476. static const __float128 Q4_5D[NQ4_5D + 1] = {
  477. 3.049977232266999249626430127217988047453E-10Q,
  478. 7.120883230531035857746096928889676144099E-8Q,
  479. 6.301786064753734446784637919554359588859E-6Q,
  480. 2.762010530095069598480766869426308077192E-4Q,
  481. 6.572163250572867859316828886203406361251E-3Q,
  482. 8.752566114841221958200215255461843397776E-2Q,
  483. 6.487654992874805093499285311075289932664E-1Q,
  484. 2.576550017826654579451615283022812801435E0Q,
  485. 5.056392229924022835364779562707348096036E0Q,
  486. 4.179770081068251464907531367859072157773E0Q,
  487. /* 1.000000000000000000000000000000000000000E0 */
  488. };
  489. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  490. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  491. Peak relative error 1.4e-36
  492. 0.25 <= 1/x <= 0.3125 */
  493. #define NQ3r2_4N 10
  494. static const __float128 Q3r2_4N[NQ3r2_4N + 1] = {
  495. 6.126167301024815034423262653066023684411E-10Q,
  496. 1.043969327113173261820028225053598975128E-7Q,
  497. 6.592927270288697027757438170153763220190E-6Q,
  498. 2.009103660938497963095652951912071336730E-4Q,
  499. 3.220543385492643525985862356352195896964E-3Q,
  500. 2.774405975730545157543417650436941650990E-2Q,
  501. 1.258114008023826384487378016636555041129E-1Q,
  502. 2.811724258266902502344701449984698323860E-1Q,
  503. 2.691837665193548059322831687432415014067E-1Q,
  504. 7.949087384900985370683770525312735605034E-2Q,
  505. 1.229509543620976530030153018986910810747E-3Q,
  506. };
  507. #define NQ3r2_4D 9
  508. static const __float128 Q3r2_4D[NQ3r2_4D + 1] = {
  509. 8.364260446128475461539941389210166156568E-9Q,
  510. 1.451301850638956578622154585560759862764E-6Q,
  511. 9.431830010924603664244578867057141839463E-5Q,
  512. 3.004105101667433434196388593004526182741E-3Q,
  513. 5.148157397848271739710011717102773780221E-2Q,
  514. 4.901089301726939576055285374953887874895E-1Q,
  515. 2.581760991981709901216967665934142240346E0Q,
  516. 7.257105880775059281391729708630912791847E0Q,
  517. 1.006014717326362868007913423810737369312E1Q,
  518. 5.879416600465399514404064187445293212470E0Q,
  519. /* 1.000000000000000000000000000000000000000E0*/
  520. };
  521. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  522. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  523. Peak relative error 3.8e-36
  524. 0.3125 <= 1/x <= 0.375 */
  525. #define NQ2r7_3r2N 9
  526. static const __float128 Q2r7_3r2N[NQ2r7_3r2N + 1] = {
  527. 7.584861620402450302063691901886141875454E-8Q,
  528. 9.300939338814216296064659459966041794591E-6Q,
  529. 4.112108906197521696032158235392604947895E-4Q,
  530. 8.515168851578898791897038357239630654431E-3Q,
  531. 8.971286321017307400142720556749573229058E-2Q,
  532. 4.885856732902956303343015636331874194498E-1Q,
  533. 1.334506268733103291656253500506406045846E0Q,
  534. 1.681207956863028164179042145803851824654E0Q,
  535. 8.165042692571721959157677701625853772271E-1Q,
  536. 9.805848115375053300608712721986235900715E-2Q,
  537. };
  538. #define NQ2r7_3r2D 9
  539. static const __float128 Q2r7_3r2D[NQ2r7_3r2D + 1] = {
  540. 1.035586492113036586458163971239438078160E-6Q,
  541. 1.301999337731768381683593636500979713689E-4Q,
  542. 5.993695702564527062553071126719088859654E-3Q,
  543. 1.321184892887881883489141186815457808785E-1Q,
  544. 1.528766555485015021144963194165165083312E0Q,
  545. 9.561463309176490874525827051566494939295E0Q,
  546. 3.203719484883967351729513662089163356911E1Q,
  547. 5.497294687660930446641539152123568668447E1Q,
  548. 4.391158169390578768508675452986948391118E1Q,
  549. 1.347836630730048077907818943625789418378E1Q,
  550. /* 1.000000000000000000000000000000000000000E0 */
  551. };
  552. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  553. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  554. Peak relative error 2.2e-35
  555. 0.375 <= 1/x <= 0.4375 */
  556. #define NQ2r3_2r7N 9
  557. static const __float128 Q2r3_2r7N[NQ2r3_2r7N + 1] = {
  558. 4.455027774980750211349941766420190722088E-7Q,
  559. 4.031998274578520170631601850866780366466E-5Q,
  560. 1.273987274325947007856695677491340636339E-3Q,
  561. 1.818754543377448509897226554179659122873E-2Q,
  562. 1.266748858326568264126353051352269875352E-1Q,
  563. 4.327578594728723821137731555139472880414E-1Q,
  564. 6.892532471436503074928194969154192615359E-1Q,
  565. 4.490775818438716873422163588640262036506E-1Q,
  566. 8.649615949297322440032000346117031581572E-2Q,
  567. 7.261345286655345047417257611469066147561E-4Q,
  568. };
  569. #define NQ2r3_2r7D 8
  570. static const __float128 Q2r3_2r7D[NQ2r3_2r7D + 1] = {
  571. 6.082600739680555266312417978064954793142E-6Q,
  572. 5.693622538165494742945717226571441747567E-4Q,
  573. 1.901625907009092204458328768129666975975E-2Q,
  574. 2.958689532697857335456896889409923371570E-1Q,
  575. 2.343124711045660081603809437993368799568E0Q,
  576. 9.665894032187458293568704885528192804376E0Q,
  577. 2.035273104990617136065743426322454881353E1Q,
  578. 2.044102010478792896815088858740075165531E1Q,
  579. 8.445937177863155827844146643468706599304E0Q,
  580. /* 1.000000000000000000000000000000000000000E0 */
  581. };
  582. /* Y0(x)cosX - J0(x)sinX = sqrt( 2/(pi x)) Q0(x),
  583. Q0(x) = 1/x (-.125 + 1/x^2 R(1/x^2))
  584. Peak relative error 3.1e-36
  585. 0.4375 <= 1/x <= 0.5 */
  586. #define NQ2_2r3N 9
  587. static const __float128 Q2_2r3N[NQ2_2r3N + 1] = {
  588. 2.817566786579768804844367382809101929314E-6Q,
  589. 2.122772176396691634147024348373539744935E-4Q,
  590. 5.501378031780457828919593905395747517585E-3Q,
  591. 6.355374424341762686099147452020466524659E-2Q,
  592. 3.539652320122661637429658698954748337223E-1Q,
  593. 9.571721066119617436343740541777014319695E-1Q,
  594. 1.196258777828426399432550698612171955305E0Q,
  595. 6.069388659458926158392384709893753793967E-1Q,
  596. 9.026746127269713176512359976978248763621E-2Q,
  597. 5.317668723070450235320878117210807236375E-4Q,
  598. };
  599. #define NQ2_2r3D 8
  600. static const __float128 Q2_2r3D[NQ2_2r3D + 1] = {
  601. 3.846924354014260866793741072933159380158E-5Q,
  602. 3.017562820057704325510067178327449946763E-3Q,
  603. 8.356305620686867949798885808540444210935E-2Q,
  604. 1.068314930499906838814019619594424586273E0Q,
  605. 6.900279623894821067017966573640732685233E0Q,
  606. 2.307667390886377924509090271780839563141E1Q,
  607. 3.921043465412723970791036825401273528513E1Q,
  608. 3.167569478939719383241775717095729233436E1Q,
  609. 1.051023841699200920276198346301543665909E1Q,
  610. /* 1.000000000000000000000000000000000000000E0*/
  611. };
  612. /* Evaluate P[n] x^n + P[n-1] x^(n-1) + ... + P[0] */
  613. static __float128
  614. neval (__float128 x, const __float128 *p, int n)
  615. {
  616. __float128 y;
  617. p += n;
  618. y = *p--;
  619. do
  620. {
  621. y = y * x + *p--;
  622. }
  623. while (--n > 0);
  624. return y;
  625. }
  626. /* Evaluate x^n+1 + P[n] x^(n) + P[n-1] x^(n-1) + ... + P[0] */
  627. static __float128
  628. deval (__float128 x, const __float128 *p, int n)
  629. {
  630. __float128 y;
  631. p += n;
  632. y = x + *p--;
  633. do
  634. {
  635. y = y * x + *p--;
  636. }
  637. while (--n > 0);
  638. return y;
  639. }
  640. /* Bessel function of the first kind, order zero. */
  641. __float128
  642. j0q (__float128 x)
  643. {
  644. __float128 xx, xinv, z, p, q, c, s, cc, ss;
  645. if (! finiteq (x))
  646. {
  647. if (x != x)
  648. return x + x;
  649. else
  650. return 0;
  651. }
  652. if (x == 0)
  653. return 1;
  654. xx = fabsq (x);
  655. if (xx <= 2)
  656. {
  657. if (xx < 0x1p-57Q)
  658. return 1;
  659. /* 0 <= x <= 2 */
  660. z = xx * xx;
  661. p = z * z * neval (z, J0_2N, NJ0_2N) / deval (z, J0_2D, NJ0_2D);
  662. p -= 0.25Q * z;
  663. p += 1;
  664. return p;
  665. }
  666. /* X = x - pi/4
  667. cos(X) = cos(x) cos(pi/4) + sin(x) sin(pi/4)
  668. = 1/sqrt(2) * (cos(x) + sin(x))
  669. sin(X) = sin(x) cos(pi/4) - cos(x) sin(pi/4)
  670. = 1/sqrt(2) * (sin(x) - cos(x))
  671. sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
  672. cf. Fdlibm. */
  673. sincosq (xx, &s, &c);
  674. ss = s - c;
  675. cc = s + c;
  676. if (xx <= FLT128_MAX / 2)
  677. {
  678. z = -cosq (xx + xx);
  679. if ((s * c) < 0)
  680. cc = z / ss;
  681. else
  682. ss = z / cc;
  683. }
  684. if (xx > 0x1p256Q)
  685. return ONEOSQPI * cc / sqrtq (xx);
  686. xinv = 1 / xx;
  687. z = xinv * xinv;
  688. if (xinv <= 0.25)
  689. {
  690. if (xinv <= 0.125)
  691. {
  692. if (xinv <= 0.0625)
  693. {
  694. p = neval (z, P16_IN, NP16_IN) / deval (z, P16_ID, NP16_ID);
  695. q = neval (z, Q16_IN, NQ16_IN) / deval (z, Q16_ID, NQ16_ID);
  696. }
  697. else
  698. {
  699. p = neval (z, P8_16N, NP8_16N) / deval (z, P8_16D, NP8_16D);
  700. q = neval (z, Q8_16N, NQ8_16N) / deval (z, Q8_16D, NQ8_16D);
  701. }
  702. }
  703. else if (xinv <= 0.1875)
  704. {
  705. p = neval (z, P5_8N, NP5_8N) / deval (z, P5_8D, NP5_8D);
  706. q = neval (z, Q5_8N, NQ5_8N) / deval (z, Q5_8D, NQ5_8D);
  707. }
  708. else
  709. {
  710. p = neval (z, P4_5N, NP4_5N) / deval (z, P4_5D, NP4_5D);
  711. q = neval (z, Q4_5N, NQ4_5N) / deval (z, Q4_5D, NQ4_5D);
  712. }
  713. } /* .25 */
  714. else /* if (xinv <= 0.5) */
  715. {
  716. if (xinv <= 0.375)
  717. {
  718. if (xinv <= 0.3125)
  719. {
  720. p = neval (z, P3r2_4N, NP3r2_4N) / deval (z, P3r2_4D, NP3r2_4D);
  721. q = neval (z, Q3r2_4N, NQ3r2_4N) / deval (z, Q3r2_4D, NQ3r2_4D);
  722. }
  723. else
  724. {
  725. p = neval (z, P2r7_3r2N, NP2r7_3r2N)
  726. / deval (z, P2r7_3r2D, NP2r7_3r2D);
  727. q = neval (z, Q2r7_3r2N, NQ2r7_3r2N)
  728. / deval (z, Q2r7_3r2D, NQ2r7_3r2D);
  729. }
  730. }
  731. else if (xinv <= 0.4375)
  732. {
  733. p = neval (z, P2r3_2r7N, NP2r3_2r7N)
  734. / deval (z, P2r3_2r7D, NP2r3_2r7D);
  735. q = neval (z, Q2r3_2r7N, NQ2r3_2r7N)
  736. / deval (z, Q2r3_2r7D, NQ2r3_2r7D);
  737. }
  738. else
  739. {
  740. p = neval (z, P2_2r3N, NP2_2r3N) / deval (z, P2_2r3D, NP2_2r3D);
  741. q = neval (z, Q2_2r3N, NQ2_2r3N) / deval (z, Q2_2r3D, NQ2_2r3D);
  742. }
  743. }
  744. p = 1 + z * p;
  745. q = z * xinv * q;
  746. q = q - 0.125Q * xinv;
  747. z = ONEOSQPI * (p * cc - q * ss) / sqrtq (xx);
  748. return z;
  749. }
  750. /* Y0(x) = 2/pi * log(x) * J0(x) + R(x^2)
  751. Peak absolute error 1.7e-36 (relative where Y0 > 1)
  752. 0 <= x <= 2 */
  753. #define NY0_2N 7
  754. static const __float128 Y0_2N[NY0_2N + 1] = {
  755. -1.062023609591350692692296993537002558155E19Q,
  756. 2.542000883190248639104127452714966858866E19Q,
  757. -1.984190771278515324281415820316054696545E18Q,
  758. 4.982586044371592942465373274440222033891E16Q,
  759. -5.529326354780295177243773419090123407550E14Q,
  760. 3.013431465522152289279088265336861140391E12Q,
  761. -7.959436160727126750732203098982718347785E9Q,
  762. 8.230845651379566339707130644134372793322E6Q,
  763. };
  764. #define NY0_2D 7
  765. static const __float128 Y0_2D[NY0_2D + 1] = {
  766. 1.438972634353286978700329883122253752192E20Q,
  767. 1.856409101981569254247700169486907405500E18Q,
  768. 1.219693352678218589553725579802986255614E16Q,
  769. 5.389428943282838648918475915779958097958E13Q,
  770. 1.774125762108874864433872173544743051653E11Q,
  771. 4.522104832545149534808218252434693007036E8Q,
  772. 8.872187401232943927082914504125234454930E5Q,
  773. 1.251945613186787532055610876304669413955E3Q,
  774. /* 1.000000000000000000000000000000000000000E0 */
  775. };
  776. static const __float128 U0 = -7.3804295108687225274343927948483016310862e-02Q;
  777. /* Bessel function of the second kind, order zero. */
  778. __float128
  779. y0q(__float128 x)
  780. {
  781. __float128 xx, xinv, z, p, q, c, s, cc, ss;
  782. if (! finiteq (x))
  783. return 1 / (x + x * x);
  784. if (x <= 0)
  785. {
  786. if (x < 0)
  787. return (zero / (zero * x));
  788. return -1 / zero; /* -inf and divide by zero exception. */
  789. }
  790. xx = fabsq (x);
  791. if (xx <= 0x1p-57)
  792. return U0 + TWOOPI * logq (x);
  793. if (xx <= 2)
  794. {
  795. /* 0 <= x <= 2 */
  796. z = xx * xx;
  797. p = neval (z, Y0_2N, NY0_2N) / deval (z, Y0_2D, NY0_2D);
  798. p = TWOOPI * logq (x) * j0q (x) + p;
  799. return p;
  800. }
  801. /* X = x - pi/4
  802. cos(X) = cos(x) cos(pi/4) + sin(x) sin(pi/4)
  803. = 1/sqrt(2) * (cos(x) + sin(x))
  804. sin(X) = sin(x) cos(pi/4) - cos(x) sin(pi/4)
  805. = 1/sqrt(2) * (sin(x) - cos(x))
  806. sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
  807. cf. Fdlibm. */
  808. sincosq (x, &s, &c);
  809. ss = s - c;
  810. cc = s + c;
  811. if (xx <= FLT128_MAX / 2)
  812. {
  813. z = -cosq (x + x);
  814. if ((s * c) < 0)
  815. cc = z / ss;
  816. else
  817. ss = z / cc;
  818. }
  819. if (xx > 0x1p256Q)
  820. return ONEOSQPI * ss / sqrtq (x);
  821. xinv = 1 / xx;
  822. z = xinv * xinv;
  823. if (xinv <= 0.25)
  824. {
  825. if (xinv <= 0.125)
  826. {
  827. if (xinv <= 0.0625)
  828. {
  829. p = neval (z, P16_IN, NP16_IN) / deval (z, P16_ID, NP16_ID);
  830. q = neval (z, Q16_IN, NQ16_IN) / deval (z, Q16_ID, NQ16_ID);
  831. }
  832. else
  833. {
  834. p = neval (z, P8_16N, NP8_16N) / deval (z, P8_16D, NP8_16D);
  835. q = neval (z, Q8_16N, NQ8_16N) / deval (z, Q8_16D, NQ8_16D);
  836. }
  837. }
  838. else if (xinv <= 0.1875)
  839. {
  840. p = neval (z, P5_8N, NP5_8N) / deval (z, P5_8D, NP5_8D);
  841. q = neval (z, Q5_8N, NQ5_8N) / deval (z, Q5_8D, NQ5_8D);
  842. }
  843. else
  844. {
  845. p = neval (z, P4_5N, NP4_5N) / deval (z, P4_5D, NP4_5D);
  846. q = neval (z, Q4_5N, NQ4_5N) / deval (z, Q4_5D, NQ4_5D);
  847. }
  848. } /* .25 */
  849. else /* if (xinv <= 0.5) */
  850. {
  851. if (xinv <= 0.375)
  852. {
  853. if (xinv <= 0.3125)
  854. {
  855. p = neval (z, P3r2_4N, NP3r2_4N) / deval (z, P3r2_4D, NP3r2_4D);
  856. q = neval (z, Q3r2_4N, NQ3r2_4N) / deval (z, Q3r2_4D, NQ3r2_4D);
  857. }
  858. else
  859. {
  860. p = neval (z, P2r7_3r2N, NP2r7_3r2N)
  861. / deval (z, P2r7_3r2D, NP2r7_3r2D);
  862. q = neval (z, Q2r7_3r2N, NQ2r7_3r2N)
  863. / deval (z, Q2r7_3r2D, NQ2r7_3r2D);
  864. }
  865. }
  866. else if (xinv <= 0.4375)
  867. {
  868. p = neval (z, P2r3_2r7N, NP2r3_2r7N)
  869. / deval (z, P2r3_2r7D, NP2r3_2r7D);
  870. q = neval (z, Q2r3_2r7N, NQ2r3_2r7N)
  871. / deval (z, Q2r3_2r7D, NQ2r3_2r7D);
  872. }
  873. else
  874. {
  875. p = neval (z, P2_2r3N, NP2_2r3N) / deval (z, P2_2r3D, NP2_2r3D);
  876. q = neval (z, Q2_2r3N, NQ2_2r3N) / deval (z, Q2_2r3D, NQ2_2r3D);
  877. }
  878. }
  879. p = 1 + z * p;
  880. q = z * xinv * q;
  881. q = q - 0.125Q * xinv;
  882. z = ONEOSQPI * (p * ss + q * cc) / sqrtq (x);
  883. return z;
  884. }