home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / m68k / math / j0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  4.1 KB  |  183 lines

  1. #include <math.h>
  2.  
  3. /*
  4.     floating point Bessel's function
  5.     of the first and second kinds
  6.     of order zero
  7.  
  8.     j0(x) returns the value of J0(x)
  9.     for all real values of x.
  10.  
  11.     There are no error returns.
  12.     Calls sin, cos, sqrt.
  13.  
  14.     There is a niggling bug in J0 which
  15.     causes errors up to 2e-16 for x in the
  16.     interval [-8,8].
  17.     The bug is caused by an inappropriate order
  18.     of summation of the series.  rhm will fix it
  19.     someday.
  20.  
  21.     Coefficients are from Hart & Cheney.
  22.     #5849 (19.22D)
  23.     #6549 (19.25D)
  24.     #6949 (19.41D)
  25.  
  26.     y0(x) returns the value of Y0(x)
  27.     for positive real values of x.
  28.     For x<=0, error number EDOM is set and a
  29.     large negative value is returned.
  30.  
  31.     Calls sin, cos, sqrt, log, j0.
  32.  
  33.     The values of Y0 have not been checked
  34.     to more than ten places.
  35.  
  36.     Coefficients are from Hart & Cheney.
  37.     #6245 (18.78D)
  38.     #6549 (19.25D)
  39.     #6949 (19.41D)
  40. */
  41.  
  42. static void asympt(double);
  43. static double pzero, qzero;
  44. static double tpi    = .6366197723675813430755350535e0;
  45. static double pio4    = .7853981633974483096156608458e0;
  46. static double p1[] = {
  47.     0.4933787251794133561816813446e21,
  48.     -.1179157629107610536038440800e21,
  49.     0.6382059341072356562289432465e19,
  50.     -.1367620353088171386865416609e18,
  51.     0.1434354939140344111664316553e16,
  52.     -.8085222034853793871199468171e13,
  53.     0.2507158285536881945555156435e11,
  54.     -.4050412371833132706360663322e8,
  55.     0.2685786856980014981415848441e5,
  56. };
  57. static double q1[] = {
  58.     0.4933787251794133562113278438e21,
  59.     0.5428918384092285160200195092e19,
  60.     0.3024635616709462698627330784e17,
  61.     0.1127756739679798507056031594e15,
  62.     0.3123043114941213172572469442e12,
  63.     0.6699987672982239671814028660e9,
  64.     0.1114636098462985378182402543e7,
  65.     0.1363063652328970604442810507e4,
  66.     1.0
  67. };
  68. static double p2[] = {
  69.     0.5393485083869438325262122897e7,
  70.     0.1233238476817638145232406055e8,
  71.     0.8413041456550439208464315611e7,
  72.     0.2016135283049983642487182349e7,
  73.     0.1539826532623911470917825993e6,
  74.     0.2485271928957404011288128951e4,
  75.     0.0,
  76. };
  77. static double q2[] = {
  78.     0.5393485083869438325560444960e7,
  79.     0.1233831022786324960844856182e8,
  80.     0.8426449050629797331554404810e7,
  81.     0.2025066801570134013891035236e7,
  82.     0.1560017276940030940592769933e6,
  83.     0.2615700736920839685159081813e4,
  84.     1.0,
  85. };
  86. static double p3[] = {
  87.     -.3984617357595222463506790588e4,
  88.     -.1038141698748464093880530341e5,
  89.     -.8239066313485606568803548860e4,
  90.     -.2365956170779108192723612816e4,
  91.     -.2262630641933704113967255053e3,
  92.     -.4887199395841261531199129300e1,
  93.     0.0,
  94. };
  95. static double q3[] = {
  96.     0.2550155108860942382983170882e6,
  97.     0.6667454239319826986004038103e6,
  98.     0.5332913634216897168722255057e6,
  99.     0.1560213206679291652539287109e6,
  100.     0.1570489191515395519392882766e5,
  101.     0.4087714673983499223402830260e3,
  102.     1.0,
  103. };
  104. static double p4[] = {
  105.     -.2750286678629109583701933175e20,
  106.     0.6587473275719554925999402049e20,
  107.     -.5247065581112764941297350814e19,
  108.     0.1375624316399344078571335453e18,
  109.     -.1648605817185729473122082537e16,
  110.     0.1025520859686394284509167421e14,
  111.     -.3436371222979040378171030138e11,
  112.     0.5915213465686889654273830069e8,
  113.     -.4137035497933148554125235152e5,
  114. };
  115. static double q4[] = {
  116.     0.3726458838986165881989980e21,
  117.     0.4192417043410839973904769661e19,
  118.     0.2392883043499781857439356652e17,
  119.     0.9162038034075185262489147968e14,
  120.     0.2613065755041081249568482092e12,
  121.     0.5795122640700729537480087915e9,
  122.     0.1001702641288906265666651753e7,
  123.     0.1282452772478993804176329391e4,
  124.     1.0,
  125. };
  126.  
  127. double j0(double arg)
  128. {
  129.     double argsq, n, d;
  130.     int i;
  131.  
  132.     if(arg < 0.) arg = -arg;
  133.     if(arg > 8.){
  134.         asympt(arg);
  135.         n = arg - pio4;
  136.         return(sqrt(tpi/arg)*(pzero*cos(n) - qzero*sin(n)));
  137.     }
  138.     argsq = arg*arg;
  139.     for(n=0,d=0,i=8;i>=0;i--){
  140.         n = n*argsq + p1[i];
  141.         d = d*argsq + q1[i];
  142.     }
  143.     return(n/d);
  144. }
  145.  
  146. double y0(double arg)
  147. {
  148.     double argsq, n, d;
  149.     int i;
  150.  
  151.     if(arg <= 0.){
  152.         return(-HUGE_VAL);
  153.     }
  154.     if(arg > 8.){
  155.         asympt(arg);
  156.         n = arg - pio4;
  157.         return(sqrt(tpi/arg)*(pzero*sin(n) + qzero*cos(n)));
  158.     }
  159.     argsq = arg*arg;
  160.     for(n=0,d=0,i=8;i>=0;i--){
  161.         n = n*argsq + p4[i];
  162.         d = d*argsq + q4[i];
  163.     }
  164.     return(n/d + tpi*j0(arg)*log(arg));
  165. }
  166.  
  167. static void asympt(double arg)
  168. {
  169.     double zsq, n, d;
  170.     int i;
  171.     zsq = 64./(arg*arg);
  172.     for(n=0,d=0,i=6;i>=0;i--){
  173.         n = n*zsq + p2[i];
  174.         d = d*zsq + q2[i];
  175.     }
  176.     pzero = n/d;
  177.     for(n=0,d=0,i=6;i>=0;i--){
  178.         n = n*zsq + p3[i];
  179.         d = d*zsq + q3[i];
  180.     }
  181.     qzero = (8./arg)*(n/d);
  182. }
  183.