zetac.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /* zetac.c
  2. *
  3. * Riemann zeta function
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, zetac();
  10. *
  11. * y = zetac( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. *
  18. *
  19. * inf.
  20. * - -x
  21. * zetac(x) = > k , x > 1,
  22. * -
  23. * k=2
  24. *
  25. * is related to the Riemann zeta function by
  26. *
  27. * Riemann zeta(x) = zetac(x) + 1.
  28. *
  29. * Extension of the function definition for x < 1 is implemented.
  30. * Zero is returned for x > log2(MAXNUM).
  31. *
  32. * An overflow error may occur for large negative x, due to the
  33. * gamma function in the reflection formula.
  34. *
  35. * ACCURACY:
  36. *
  37. * Tabulated values have full machine accuracy.
  38. *
  39. * Relative error:
  40. * arithmetic domain # trials peak rms
  41. * IEEE 1,50 10000 9.8e-16 1.3e-16
  42. * DEC 1,50 2000 1.1e-16 1.9e-17
  43. *
  44. *
  45. */
  46. /*
  47. Cephes Math Library Release 2.8: June, 2000
  48. Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
  49. */
  50. #include "mconf.h"
  51. extern double MAXNUM, PI;
  52. /* Riemann zeta(x) - 1
  53. * for integer arguments between 0 and 30.
  54. */
  55. #ifdef UNK
  56. static double azetac[] = {
  57. -1.50000000000000000000E0, 1.70141183460469231730E38, /* infinity. */
  58. 6.44934066848226436472E-1, 2.02056903159594285400E-1,
  59. 8.23232337111381915160E-2, 3.69277551433699263314E-2,
  60. 1.73430619844491397145E-2, 8.34927738192282683980E-3,
  61. 4.07735619794433937869E-3, 2.00839282608221441785E-3,
  62. 9.94575127818085337146E-4, 4.94188604119464558702E-4,
  63. 2.46086553308048298638E-4, 1.22713347578489146752E-4,
  64. 6.12481350587048292585E-5, 3.05882363070204935517E-5,
  65. 1.52822594086518717326E-5, 7.63719763789976227360E-6,
  66. 3.81729326499983985646E-6, 1.90821271655393892566E-6,
  67. 9.53962033872796113152E-7, 4.76932986787806463117E-7,
  68. 2.38450502727732990004E-7, 1.19219925965311073068E-7,
  69. 5.96081890512594796124E-8, 2.98035035146522801861E-8,
  70. 1.49015548283650412347E-8, 7.45071178983542949198E-9,
  71. 3.72533402478845705482E-9, 1.86265972351304900640E-9,
  72. 9.31327432419668182872E-10};
  73. #endif
  74. #ifdef DEC
  75. static unsigned short azetac[] = {
  76. 0140300, 0000000, 0000000, 0000000, 0077777, 0177777, 0177777, 0177777,
  77. 0040045, 0015146, 0022460, 0076462, 0037516, 0164001, 0036001, 0104116,
  78. 0037250, 0114425, 0061754, 0022033, 0037027, 0040616, 0145174, 0146670,
  79. 0036616, 0011411, 0100444, 0104437, 0036410, 0145550, 0051474, 0161067,
  80. 0036205, 0115527, 0141434, 0133506, 0036003, 0117475, 0100553, 0053403,
  81. 0035602, 0056147, 0045567, 0027703, 0035401, 0106157, 0111054, 0145242,
  82. 0035201, 0002455, 0113151, 0101015, 0035000, 0126235, 0004273, 0157260,
  83. 0034600, 0071127, 0112647, 0005261, 0034400, 0045736, 0057610, 0157550,
  84. 0034200, 0031146, 0172621, 0074172, 0034000, 0020603, 0115503, 0032007,
  85. 0033600, 0013114, 0124672, 0023135, 0033400, 0007330, 0043715, 0151117,
  86. 0033200, 0004742, 0145043, 0033514, 0033000, 0003225, 0152624, 0004411,
  87. 0032600, 0002143, 0033166, 0035746, 0032400, 0001354, 0074234, 0026143,
  88. 0032200, 0000762, 0147776, 0170220, 0032000, 0000514, 0072452, 0130631,
  89. 0031600, 0000335, 0114266, 0063315, 0031400, 0000223, 0132710, 0041045,
  90. 0031200, 0000142, 0073202, 0153426, 0031000, 0000101, 0121400, 0152065,
  91. 0030600, 0000053, 0140525, 0072761};
  92. #endif
  93. #ifdef IBMPC
  94. static unsigned short azetac[] = {
  95. 0x0000, 0x0000, 0x0000, 0xbff8, 0xffff, 0xffff, 0xffff, 0x7fef, 0x0fa6,
  96. 0xc4a6, 0xa34c, 0x3fe4, 0x310a, 0x2780, 0xdd00, 0x3fc9, 0x8483, 0xac7d,
  97. 0x1322, 0x3fb5, 0x99b7, 0xd94f, 0xe831, 0x3fa2, 0x9124, 0x3024, 0xc261,
  98. 0x3f91, 0x9c47, 0x0a67, 0x196d, 0x3f81, 0x96e9, 0xf863, 0xb36a, 0x3f70,
  99. 0x6ae0, 0xb02d, 0x73e7, 0x3f60, 0xe5f8, 0xe96e, 0x4b8c, 0x3f50, 0x9954,
  100. 0xf245, 0x318d, 0x3f40, 0x3042, 0xb2cd, 0x20a5, 0x3f30, 0x7bd6, 0xa117,
  101. 0x1593, 0x3f20, 0xe156, 0xf2b4, 0x0e4a, 0x3f10, 0x1bed, 0xcbf1, 0x097b,
  102. 0x3f00, 0x2f0f, 0xdeb2, 0x064c, 0x3ef0, 0x6681, 0x7368, 0x0430, 0x3ee0,
  103. 0x44cc, 0x9537, 0x02c9, 0x3ed0, 0xba4a, 0x08f9, 0x01db, 0x3ec0, 0x66ea,
  104. 0x5944, 0x013c, 0x3eb0, 0x8121, 0xbab2, 0x00d2, 0x3ea0, 0xc77d, 0x66ce,
  105. 0x008c, 0x3e90, 0x858c, 0x8f13, 0x005d, 0x3e80, 0xde12, 0x59ff, 0x003e,
  106. 0x3e70, 0x5633, 0x8ea5, 0x0029, 0x3e60, 0xccda, 0xb316, 0x001b, 0x3e50,
  107. 0x0845, 0x76b9, 0x0012, 0x3e40, 0x5ae3, 0x4ed0, 0x000c, 0x3e30, 0x1a87,
  108. 0x3460, 0x0008, 0x3e20, 0xaebe, 0x782a, 0x0005, 0x3e10};
  109. #endif
  110. #ifdef MIEEE
  111. static unsigned short azetac[] = {
  112. 0xbff8, 0x0000, 0x0000, 0x0000, 0x7fef, 0xffff, 0xffff, 0xffff, 0x3fe4,
  113. 0xa34c, 0xc4a6, 0x0fa6, 0x3fc9, 0xdd00, 0x2780, 0x310a, 0x3fb5, 0x1322,
  114. 0xac7d, 0x8483, 0x3fa2, 0xe831, 0xd94f, 0x99b7, 0x3f91, 0xc261, 0x3024,
  115. 0x9124, 0x3f81, 0x196d, 0x0a67, 0x9c47, 0x3f70, 0xb36a, 0xf863, 0x96e9,
  116. 0x3f60, 0x73e7, 0xb02d, 0x6ae0, 0x3f50, 0x4b8c, 0xe96e, 0xe5f8, 0x3f40,
  117. 0x318d, 0xf245, 0x9954, 0x3f30, 0x20a5, 0xb2cd, 0x3042, 0x3f20, 0x1593,
  118. 0xa117, 0x7bd6, 0x3f10, 0x0e4a, 0xf2b4, 0xe156, 0x3f00, 0x097b, 0xcbf1,
  119. 0x1bed, 0x3ef0, 0x064c, 0xdeb2, 0x2f0f, 0x3ee0, 0x0430, 0x7368, 0x6681,
  120. 0x3ed0, 0x02c9, 0x9537, 0x44cc, 0x3ec0, 0x01db, 0x08f9, 0xba4a, 0x3eb0,
  121. 0x013c, 0x5944, 0x66ea, 0x3ea0, 0x00d2, 0xbab2, 0x8121, 0x3e90, 0x008c,
  122. 0x66ce, 0xc77d, 0x3e80, 0x005d, 0x8f13, 0x858c, 0x3e70, 0x003e, 0x59ff,
  123. 0xde12, 0x3e60, 0x0029, 0x8ea5, 0x5633, 0x3e50, 0x001b, 0xb316, 0xccda,
  124. 0x3e40, 0x0012, 0x76b9, 0x0845, 0x3e30, 0x000c, 0x4ed0, 0x5ae3, 0x3e20,
  125. 0x0008, 0x3460, 0x1a87, 0x3e10, 0x0005, 0x782a, 0xaebe};
  126. #endif
  127. /* 2**x (1 - 1/x) (zeta(x) - 1) = P(1/x)/Q(1/x), 1 <= x <= 10 */
  128. #ifdef UNK
  129. static double P[9] = {
  130. 5.85746514569725319540E11, 2.57534127756102572888E11,
  131. 4.87781159567948256438E10, 5.15399538023885770696E9,
  132. 3.41646073514754094281E8, 1.60837006880656492731E7,
  133. 5.92785467342109522998E5, 1.51129169964938823117E4,
  134. 2.01822444485997955865E2,
  135. };
  136. static double Q[8] = {
  137. /* 1.00000000000000000000E0,*/
  138. 3.90497676373371157516E11, 5.22858235368272161797E10,
  139. 5.64451517271280543351E9, 3.39006746015350418834E8,
  140. 1.79410371500126453702E7, 5.66666825131384797029E5,
  141. 1.60382976810944131506E4, 1.96436237223387314144E2,
  142. };
  143. #endif
  144. #ifdef DEC
  145. static unsigned short P[36] = {
  146. 0052010, 0060466, 0101211, 0134657, 0051557, 0154353, 0135060, 0064411,
  147. 0051065, 0133157, 0133514, 0133633, 0050231, 0114735, 0035036, 0111344,
  148. 0047242, 0164327, 0146036, 0033545, 0046165, 0065364, 0130045, 0011005,
  149. 0045020, 0134427, 0075073, 0134107, 0043554, 0021653, 0000440, 0177426,
  150. 0042111, 0151213, 0134312, 0021402,
  151. };
  152. static unsigned short Q[32] = {
  153. /*0040200,0000000,0000000,0000000,*/
  154. 0051665, 0153363, 0054252, 0137010, 0051102, 0143645, 0121415, 0036107,
  155. 0050250, 0034073, 0131133, 0036465, 0047241, 0123250, 0150037, 0070012,
  156. 0046210, 0160426, 0111463, 0116507, 0045012, 0054255, 0031674, 0173612,
  157. 0043572, 0114460, 0151520, 0012221, 0042104, 0067655, 0037037, 0137421,
  158. };
  159. #endif
  160. #ifdef IBMPC
  161. static unsigned short P[36] = {
  162. 0x3736, 0xd051, 0x0c26, 0x4261, 0x0d21, 0x7746, 0xfb1d, 0x424d, 0x96f3,
  163. 0xf6e9, 0xb6cd, 0x4226, 0xd25c, 0xa743, 0x333b, 0x41f3, 0xc6ed, 0xf983,
  164. 0x5d1a, 0x41b4, 0xa241, 0x9604, 0xad5e, 0x416e, 0x7709, 0xef47, 0x1722,
  165. 0x4122, 0x1fe3, 0x6024, 0x8475, 0x40cd, 0x4460, 0x7719, 0x3a51, 0x4069,
  166. };
  167. static unsigned short Q[32] = {
  168. /*0x0000,0x0000,0x0000,0x3ff0,*/
  169. 0x57c1, 0x6b15, 0xbade, 0x4256, 0xa789, 0xb461, 0x58f4, 0x4228,
  170. 0x67a7, 0x764b, 0x0707, 0x41f5, 0xee01, 0x1a03, 0x34d5, 0x41b4,
  171. 0x73a9, 0xd266, 0x1c22, 0x4171, 0x9ef1, 0xa677, 0x4b15, 0x4121,
  172. 0x0292, 0x1a6a, 0x5326, 0x40cf, 0xf7e2, 0xa7c3, 0x8df5, 0x4068,
  173. };
  174. #endif
  175. #ifdef MIEEE
  176. static unsigned short P[36] = {
  177. 0x4261, 0x0c26, 0xd051, 0x3736, 0x424d, 0xfb1d, 0x7746, 0x0d21, 0x4226,
  178. 0xb6cd, 0xf6e9, 0x96f3, 0x41f3, 0x333b, 0xa743, 0xd25c, 0x41b4, 0x5d1a,
  179. 0xf983, 0xc6ed, 0x416e, 0xad5e, 0x9604, 0xa241, 0x4122, 0x1722, 0xef47,
  180. 0x7709, 0x40cd, 0x8475, 0x6024, 0x1fe3, 0x4069, 0x3a51, 0x7719, 0x4460,
  181. };
  182. static unsigned short Q[32] = {
  183. /*0x3ff0,0x0000,0x0000,0x0000,*/
  184. 0x4256, 0xbade, 0x6b15, 0x57c1, 0x4228, 0x58f4, 0xb461, 0xa789,
  185. 0x41f5, 0x0707, 0x764b, 0x67a7, 0x41b4, 0x34d5, 0x1a03, 0xee01,
  186. 0x4171, 0x1c22, 0xd266, 0x73a9, 0x4121, 0x4b15, 0xa677, 0x9ef1,
  187. 0x40cf, 0x5326, 0x1a6a, 0x0292, 0x4068, 0x8df5, 0xa7c3, 0xf7e2,
  188. };
  189. #endif
  190. /* log(zeta(x) - 1 - 2**-x), 10 <= x <= 50 */
  191. #ifdef UNK
  192. static double A[11] = {
  193. 8.70728567484590192539E6, 1.76506865670346462757E8,
  194. 2.60889506707483264896E10, 5.29806374009894791647E11,
  195. 2.26888156119238241487E13, 3.31884402932705083599E14,
  196. 5.13778997975868230192E15, -1.98123688133907171455E15,
  197. -9.92763810039983572356E16, 7.82905376180870586444E16,
  198. 9.26786275768927717187E16,
  199. };
  200. static double B[10] = {
  201. /* 1.00000000000000000000E0,*/
  202. -7.92625410563741062861E6, -1.60529969932920229676E8,
  203. -2.37669260975543221788E10, -4.80319584350455169857E11,
  204. -2.07820961754173320170E13, -2.96075404507272223680E14,
  205. -4.86299103694609136686E15, 5.34589509675789930199E15,
  206. 5.71464111092297631292E16, -1.79915597658676556828E16,
  207. };
  208. #endif
  209. #ifdef DEC
  210. static unsigned short A[44] = {
  211. 0046004, 0156325, 0126302, 0131567, 0047050, 0052177, 0015271, 0136466,
  212. 0050702, 0060271, 0070727, 0171112, 0051766, 0132727, 0064363, 0145042,
  213. 0053245, 0012466, 0056000, 0117230, 0054226, 0166155, 0174275, 0170213,
  214. 0055222, 0003127, 0112544, 0101322, 0154741, 0036625, 0010346, 0053767,
  215. 0156260, 0054653, 0154052, 0031113, 0056213, 0011152, 0021000, 0007111,
  216. 0056244, 0120534, 0040576, 0163262,
  217. };
  218. static unsigned short B[40] = {
  219. /*0040200,0000000,0000000,0000000,*/
  220. 0145761, 0161734, 0033026, 0015520, 0147031, 0013743, 0017355, 0036703,
  221. 0150661, 0011720, 0061061, 0136402, 0151737, 0125216, 0070274, 0164414,
  222. 0153227, 0032653, 0127211, 0145250, 0154206, 0121666, 0123774, 0042035,
  223. 0155212, 0033352, 0125154, 0132533, 0055227, 0170201, 0110775, 0072132,
  224. 0056113, 0003133, 0127132, 0122303, 0155577, 0126351, 0141462, 0171037,
  225. };
  226. #endif
  227. #ifdef IBMPC
  228. static unsigned short A[44] = {
  229. 0x566f, 0xb598, 0x9b9a, 0x4160, 0x37a7, 0xe357, 0x0a8f, 0x41a5, 0xfe49,
  230. 0x2e3a, 0x4c17, 0x4218, 0x7944, 0xed1e, 0xd6ba, 0x425e, 0x13d3, 0xcb80,
  231. 0xa2a6, 0x42b4, 0xbe11, 0xbf17, 0xdd8d, 0x42f2, 0x905a, 0xf2ac, 0x40ca,
  232. 0x4332, 0xcaff, 0xa21c, 0x27b2, 0xc31c, 0x4649, 0x7b05, 0x0b35, 0xc376,
  233. 0x01c9, 0x4440, 0x624d, 0x4371, 0xdcd6, 0x882f, 0x942b, 0x4374,
  234. };
  235. static unsigned short B[40] = {
  236. /*0x0000,0x0000,0x0000,0x3ff0,*/
  237. 0xc36a, 0x86c2, 0x3c7b, 0xc15e, 0xa7b8, 0x63dd, 0x22fc, 0xc1a3,
  238. 0x37a0, 0x0c46, 0x227a, 0xc216, 0x9d22, 0xce17, 0xf551, 0xc25b,
  239. 0x3955, 0x75d1, 0xe6b5, 0xc2b2, 0x8884, 0xd4ff, 0xd476, 0xc2f0,
  240. 0x96ab, 0x554d, 0x46dd, 0xc331, 0xae8b, 0x323f, 0xfe10, 0x4332,
  241. 0x5498, 0x75cb, 0x60cb, 0x4369, 0x5e44, 0x3866, 0xf59d, 0xc34f,
  242. };
  243. #endif
  244. #ifdef MIEEE
  245. static unsigned short A[44] = {
  246. 0x4160, 0x9b9a, 0xb598, 0x566f, 0x41a5, 0x0a8f, 0xe357, 0x37a7, 0x4218,
  247. 0x4c17, 0x2e3a, 0xfe49, 0x425e, 0xd6ba, 0xed1e, 0x7944, 0x42b4, 0xa2a6,
  248. 0xcb80, 0x13d3, 0x42f2, 0xdd8d, 0xbf17, 0xbe11, 0x4332, 0x40ca, 0xf2ac,
  249. 0x905a, 0xc31c, 0x27b2, 0xa21c, 0xcaff, 0xc376, 0x0b35, 0x7b05, 0x4649,
  250. 0x4371, 0x624d, 0x4440, 0x01c9, 0x4374, 0x942b, 0x882f, 0xdcd6,
  251. };
  252. static unsigned short B[40] = {
  253. /*0x3ff0,0x0000,0x0000,0x0000,*/
  254. 0xc15e, 0x3c7b, 0x86c2, 0xc36a, 0xc1a3, 0x22fc, 0x63dd, 0xa7b8,
  255. 0xc216, 0x227a, 0x0c46, 0x37a0, 0xc25b, 0xf551, 0xce17, 0x9d22,
  256. 0xc2b2, 0xe6b5, 0x75d1, 0x3955, 0xc2f0, 0xd476, 0xd4ff, 0x8884,
  257. 0xc331, 0x46dd, 0x554d, 0x96ab, 0x4332, 0xfe10, 0x323f, 0xae8b,
  258. 0x4369, 0x60cb, 0x75cb, 0x5498, 0xc34f, 0xf59d, 0x3866, 0x5e44,
  259. };
  260. #endif
  261. /* (1-x) (zeta(x) - 1), 0 <= x <= 1 */
  262. #ifdef UNK
  263. static double R[6] = {
  264. -3.28717474506562731748E-1, 1.55162528742623950834E1,
  265. -2.48762831680821954401E2, 1.01050368053237678329E3,
  266. 1.26726061410235149405E4, -1.11578094770515181334E5,
  267. };
  268. static double S[5] = {
  269. /* 1.00000000000000000000E0,*/
  270. 1.95107674914060531512E1, 3.17710311750646984099E2,
  271. 3.03835500874445748734E3, 2.03665876435770579345E4,
  272. 7.43853965136767874343E4,
  273. };
  274. #endif
  275. #ifdef DEC
  276. static unsigned short R[24] = {
  277. 0137650, 0046650, 0022502, 0040316, 0041170, 0041222, 0057666, 0142216,
  278. 0142170, 0141510, 0167741, 0075646, 0042574, 0120074, 0046505, 0106053,
  279. 0043506, 0001154, 0130073, 0101413, 0144331, 0166414, 0020560, 0131652,
  280. };
  281. static unsigned short S[20] = {
  282. /*0040200,0000000,0000000,0000000,*/
  283. 0041234, 0013015, 0042073, 0113570, 0042236, 0155353, 0077325,
  284. 0077445, 0043075, 0162656, 0016646, 0031723, 0043637, 0016454,
  285. 0157636, 0071126, 0044221, 0044262, 0140365, 0146434,
  286. };
  287. #endif
  288. #ifdef IBMPC
  289. static unsigned short R[24] = {
  290. 0x481a, 0x04a8, 0x09b5, 0xbfd5, 0xd892, 0x4bf6, 0x0852, 0x402f,
  291. 0x2f75, 0x1dfc, 0x1869, 0xc06f, 0xb185, 0x89a8, 0x9407, 0x408f,
  292. 0x7061, 0x9607, 0xc04d, 0x40c8, 0x1675, 0x842e, 0x3da1, 0xc0fb,
  293. };
  294. static unsigned short S[20] = {
  295. /*0x0000,0x0000,0x0000,0x3ff0,*/
  296. 0x72ef, 0xa887, 0x82c1, 0x4033, 0xafe5, 0x6fda, 0xdb5d,
  297. 0x4073, 0xc67a, 0xc3b4, 0xbcb5, 0x40a7, 0xce4b, 0x9bf3,
  298. 0xe3a5, 0x40d3, 0xb9a3, 0x581e, 0x2916, 0x40f2,
  299. };
  300. #endif
  301. #ifdef MIEEE
  302. static unsigned short R[24] = {
  303. 0xbfd5, 0x09b5, 0x04a8, 0x481a, 0x402f, 0x0852, 0x4bf6, 0xd892,
  304. 0xc06f, 0x1869, 0x1dfc, 0x2f75, 0x408f, 0x9407, 0x89a8, 0xb185,
  305. 0x40c8, 0xc04d, 0x9607, 0x7061, 0xc0fb, 0x3da1, 0x842e, 0x1675,
  306. };
  307. static unsigned short S[20] = {
  308. /*0x3ff0,0x0000,0x0000,0x0000,*/
  309. 0x4033, 0x82c1, 0xa887, 0x72ef, 0x4073, 0xdb5d, 0x6fda,
  310. 0xafe5, 0x40a7, 0xbcb5, 0xc3b4, 0xc67a, 0x40d3, 0xe3a5,
  311. 0x9bf3, 0xce4b, 0x40f2, 0x2916, 0x581e, 0xb9a3,
  312. };
  313. #endif
  314. #define MAXL2 127
  315. /*
  316. * Riemann zeta function, minus one
  317. */
  318. #ifdef ANSIPROT
  319. extern double sin(double);
  320. extern double floor(double);
  321. extern double gamma(double);
  322. extern double pow(double, double);
  323. extern double exp(double);
  324. extern double polevl(double, void *, int);
  325. extern double p1evl(double, void *, int);
  326. double zetac(double);
  327. #else
  328. double sin(), floor(), gamma(), pow(), exp();
  329. double polevl(), p1evl(), zetac();
  330. #endif
  331. extern double MACHEP;
  332. double zetac(x) double x;
  333. {
  334. int i;
  335. double a, b, s, w;
  336. if (x < 0.0) {
  337. #ifdef DEC
  338. if (x < -30.8148)
  339. #else
  340. if (x < -170.6243)
  341. #endif
  342. {
  343. mtherr("zetac", OVERFLOW);
  344. return (0.0);
  345. }
  346. s = 1.0 - x;
  347. w = zetac(s);
  348. b = sin(0.5 * PI * x) * pow(2.0 * PI, x) * gamma(s) * (1.0 + w) / PI;
  349. return (b - 1.0);
  350. }
  351. if (x >= MAXL2)
  352. return (0.0); /* because first term is 2**-x */
  353. /* Tabulated values for integer argument */
  354. w = floor(x);
  355. if (w == x) {
  356. i = x;
  357. if (i < 31) {
  358. #ifdef UNK
  359. return (azetac[i]);
  360. #else
  361. return (*(double *)&azetac[4 * i]);
  362. #endif
  363. }
  364. }
  365. if (x < 1.0) {
  366. w = 1.0 - x;
  367. a = polevl(x, R, 5) / (w * p1evl(x, S, 5));
  368. return (a);
  369. }
  370. if (x == 1.0) {
  371. mtherr("zetac", SING);
  372. return (MAXNUM);
  373. }
  374. if (x <= 10.0) {
  375. b = pow(2.0, x) * (x - 1.0);
  376. w = 1.0 / x;
  377. s = (x * polevl(w, P, 8)) / (b * p1evl(w, Q, 8));
  378. return (s);
  379. }
  380. if (x <= 50.0) {
  381. b = pow(2.0, -x);
  382. w = polevl(x, A, 10) / p1evl(x, B, 10);
  383. w = exp(w) + b;
  384. return (w);
  385. }
  386. /* Basic sum of inverse powers */
  387. s = 0.0;
  388. a = 1.0;
  389. do {
  390. a += 2.0;
  391. b = pow(a, -x);
  392. s += b;
  393. } while (b / s > MACHEP);
  394. b = pow(2.0, -x);
  395. s = (s + b) / (1.0 - b);
  396. return (s);
  397. }