zetac.c 14 KB

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