gamma.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* gamma.c
  2. *
  3. * Gamma function
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, gamma();
  10. * extern int sgngam;
  11. *
  12. * y = gamma( x );
  13. *
  14. *
  15. *
  16. * DESCRIPTION:
  17. *
  18. * Returns gamma function of the argument. The result is
  19. * correctly signed, and the sign (+1 or -1) is also
  20. * returned in a global (extern) variable named sgngam.
  21. * This variable is also filled in by the logarithmic gamma
  22. * function lgam().
  23. *
  24. * Arguments |x| <= 34 are reduced by recurrence and the function
  25. * approximated by a rational function of degree 6/7 in the
  26. * interval (2,3). Large arguments are handled by Stirling's
  27. * formula. Large negative arguments are made positive using
  28. * a reflection formula.
  29. *
  30. *
  31. * ACCURACY:
  32. *
  33. * Relative error:
  34. * arithmetic domain # trials peak rms
  35. * DEC -34, 34 10000 1.3e-16 2.5e-17
  36. * IEEE -170,-33 20000 2.3e-15 3.3e-16
  37. * IEEE -33, 33 20000 9.4e-16 2.2e-16
  38. * IEEE 33, 171.6 20000 2.3e-15 3.2e-16
  39. *
  40. * Error for arguments outside the test range will be larger
  41. * owing to error amplification by the exponential function.
  42. *
  43. */
  44. /* lgam()
  45. *
  46. * Natural logarithm of gamma function
  47. *
  48. *
  49. *
  50. * SYNOPSIS:
  51. *
  52. * double x, y, lgam();
  53. * extern int sgngam;
  54. *
  55. * y = lgam( x );
  56. *
  57. *
  58. *
  59. * DESCRIPTION:
  60. *
  61. * Returns the base e (2.718...) logarithm of the absolute
  62. * value of the gamma function of the argument.
  63. * The sign (+1 or -1) of the gamma function is returned in a
  64. * global (extern) variable named sgngam.
  65. *
  66. * For arguments greater than 13, the logarithm of the gamma
  67. * function is approximated by the logarithmic version of
  68. * Stirling's formula using a polynomial approximation of
  69. * degree 4. Arguments between -33 and +33 are reduced by
  70. * recurrence to the interval [2,3] of a rational approximation.
  71. * The cosecant reflection formula is employed for arguments
  72. * less than -33.
  73. *
  74. * Arguments greater than MAXLGM return MAXNUM and an error
  75. * message. MAXLGM = 2.035093e36 for DEC
  76. * arithmetic or 2.556348e305 for IEEE arithmetic.
  77. *
  78. *
  79. *
  80. * ACCURACY:
  81. *
  82. *
  83. * arithmetic domain # trials peak rms
  84. * DEC 0, 3 7000 5.2e-17 1.3e-17
  85. * DEC 2.718, 2.035e36 5000 3.9e-17 9.9e-18
  86. * IEEE 0, 3 28000 5.4e-16 1.1e-16
  87. * IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17
  88. * The error criterion was relative when the function magnitude
  89. * was greater than one but absolute when it was less than one.
  90. *
  91. * The following test used the relative error criterion, though
  92. * at certain points the relative error could be much higher than
  93. * indicated.
  94. * IEEE -200, -4 10000 4.8e-16 1.3e-16
  95. *
  96. */
  97. /* gamma.c */
  98. /* gamma function */
  99. /*
  100. Cephes Math Library Release 2.8: June, 2000
  101. Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
  102. */
  103. #include "mconf.h"
  104. #ifdef UNK
  105. static double P[] = {1.60119522476751861407E-4, 1.19135147006586384913E-3,
  106. 1.04213797561761569935E-2, 4.76367800457137231464E-2,
  107. 2.07448227648435975150E-1, 4.94214826801497100753E-1,
  108. 9.99999999999999996796E-1};
  109. static double Q[] = {-2.31581873324120129819E-5, 5.39605580493303397842E-4,
  110. -4.45641913851797240494E-3, 1.18139785222060435552E-2,
  111. 3.58236398605498653373E-2, -2.34591795718243348568E-1,
  112. 7.14304917030273074085E-2, 1.00000000000000000320E0};
  113. #define MAXGAM 171.624376956302725
  114. static double LOGPI = 1.14472988584940017414;
  115. #endif
  116. #ifdef DEC
  117. static unsigned short P[] = {
  118. 0035047, 0162701, 0146301, 0005234, 0035634, 0023437, 0032065,
  119. 0176530, 0036452, 0137157, 0047330, 0122574, 0037103, 0017310,
  120. 0143041, 0017232, 0037524, 0066516, 0162563, 0164605, 0037775,
  121. 0004671, 0146237, 0014222, 0040200, 0000000, 0000000, 0000000};
  122. static unsigned short Q[] = {
  123. 0134302, 0041724, 0020006, 0116565, 0035415, 0072121, 0044251, 0025634,
  124. 0136222, 0003447, 0035205, 0121114, 0036501, 0107552, 0154335, 0104271,
  125. 0037022, 0135717, 0014776, 0171471, 0137560, 0034324, 0165024, 0037021,
  126. 0037222, 0045046, 0047151, 0161213, 0040200, 0000000, 0000000, 0000000};
  127. #define MAXGAM 34.84425627277176174
  128. static unsigned short LPI[4] = {
  129. 0040222,
  130. 0103202,
  131. 0043475,
  132. 0006750,
  133. };
  134. #define LOGPI *(double *)LPI
  135. #endif
  136. #ifdef IBMPC
  137. static unsigned short P[] = {0x2153, 0x3998, 0xfcb8, 0x3f24, 0xbfab, 0xe686,
  138. 0x84e3, 0x3f53, 0x14b0, 0xe9db, 0x57cd, 0x3f85,
  139. 0x23d3, 0x18c4, 0x63d9, 0x3fa8, 0x7d31, 0xdcae,
  140. 0x8da9, 0x3fca, 0xe312, 0x3993, 0xa137, 0x3fdf,
  141. 0x0000, 0x0000, 0x0000, 0x3ff0};
  142. static unsigned short Q[] = {
  143. 0xd3af, 0x8400, 0x487a, 0xbef8, 0x2573, 0x2915, 0xae8a, 0x3f41,
  144. 0xb44a, 0xe750, 0x40e4, 0xbf72, 0xb117, 0x5b1b, 0x31ed, 0x3f88,
  145. 0xde67, 0xe33f, 0x5779, 0x3fa2, 0x87c2, 0x9d42, 0x071a, 0xbfce,
  146. 0x3c51, 0xc9cd, 0x4944, 0x3fb2, 0x0000, 0x0000, 0x0000, 0x3ff0};
  147. #define MAXGAM 171.624376956302725
  148. static unsigned short LPI[4] = {
  149. 0xa1bd,
  150. 0x48e7,
  151. 0x50d0,
  152. 0x3ff2,
  153. };
  154. #define LOGPI *(double *)LPI
  155. #endif
  156. #ifdef MIEEE
  157. static unsigned short P[] = {0x3f24, 0xfcb8, 0x3998, 0x2153, 0x3f53, 0x84e3,
  158. 0xe686, 0xbfab, 0x3f85, 0x57cd, 0xe9db, 0x14b0,
  159. 0x3fa8, 0x63d9, 0x18c4, 0x23d3, 0x3fca, 0x8da9,
  160. 0xdcae, 0x7d31, 0x3fdf, 0xa137, 0x3993, 0xe312,
  161. 0x3ff0, 0x0000, 0x0000, 0x0000};
  162. static unsigned short Q[] = {
  163. 0xbef8, 0x487a, 0x8400, 0xd3af, 0x3f41, 0xae8a, 0x2915, 0x2573,
  164. 0xbf72, 0x40e4, 0xe750, 0xb44a, 0x3f88, 0x31ed, 0x5b1b, 0xb117,
  165. 0x3fa2, 0x5779, 0xe33f, 0xde67, 0xbfce, 0x071a, 0x9d42, 0x87c2,
  166. 0x3fb2, 0x4944, 0xc9cd, 0x3c51, 0x3ff0, 0x0000, 0x0000, 0x0000};
  167. #define MAXGAM 171.624376956302725
  168. static unsigned short LPI[4] = {
  169. 0x3ff2,
  170. 0x50d0,
  171. 0x48e7,
  172. 0xa1bd,
  173. };
  174. #define LOGPI *(double *)LPI
  175. #endif
  176. /* Stirling's formula for the gamma function */
  177. #if UNK
  178. static double STIR[5] = {
  179. 7.87311395793093628397E-4, -2.29549961613378126380E-4,
  180. -2.68132617805781232825E-3, 3.47222221605458667310E-3,
  181. 8.33333333333482257126E-2,
  182. };
  183. #define MAXSTIR 143.01608
  184. static double SQTPI = 2.50662827463100050242E0;
  185. #endif
  186. #if DEC
  187. static unsigned short STIR[20] = {
  188. 0035516, 0061622, 0144553, 0112224, 0135160, 0131531, 0037460,
  189. 0165740, 0136057, 0134460, 0037242, 0077270, 0036143, 0107070,
  190. 0156306, 0027751, 0037252, 0125252, 0125252, 0146064,
  191. };
  192. #define MAXSTIR 26.77
  193. static unsigned short SQT[4] = {
  194. 0040440,
  195. 0066230,
  196. 0177661,
  197. 0034055,
  198. };
  199. #define SQTPI *(double *)SQT
  200. #endif
  201. #if IBMPC
  202. static unsigned short STIR[20] = {
  203. 0x7293, 0x592d, 0xcc72, 0x3f49, 0x1d7c, 0x27e6, 0x166b,
  204. 0xbf2e, 0x4fd7, 0x07d4, 0xf726, 0xbf65, 0xc5fd, 0x1b98,
  205. 0x71c7, 0x3f6c, 0x5986, 0x5555, 0x5555, 0x3fb5,
  206. };
  207. #define MAXSTIR 143.01608
  208. static unsigned short SQT[4] = {
  209. 0x2706,
  210. 0x1ff6,
  211. 0x0d93,
  212. 0x4004,
  213. };
  214. #define SQTPI *(double *)SQT
  215. #endif
  216. #if MIEEE
  217. static unsigned short STIR[20] = {
  218. 0x3f49, 0xcc72, 0x592d, 0x7293, 0xbf2e, 0x166b, 0x27e6,
  219. 0x1d7c, 0xbf65, 0xf726, 0x07d4, 0x4fd7, 0x3f6c, 0x71c7,
  220. 0x1b98, 0xc5fd, 0x3fb5, 0x5555, 0x5555, 0x5986,
  221. };
  222. #define MAXSTIR 143.01608
  223. static unsigned short SQT[4] = {
  224. 0x4004,
  225. 0x0d93,
  226. 0x1ff6,
  227. 0x2706,
  228. };
  229. #define SQTPI *(double *)SQT
  230. #endif
  231. int sgngam = 0;
  232. extern int sgngam;
  233. extern double MAXLOG, MAXNUM, PI;
  234. #ifdef ANSIPROT
  235. extern double pow(double, double);
  236. extern double log(double);
  237. extern double exp(double);
  238. extern double sin(double);
  239. extern double polevl(double, void *, int);
  240. extern double p1evl(double, void *, int);
  241. extern double floor(double);
  242. extern double fabs(double);
  243. extern int isnan(double);
  244. extern int isfinite(double);
  245. static double stirf(double);
  246. double lgam(double);
  247. #else
  248. double pow(), log(), exp(), sin(), polevl(), p1evl(), floor(), fabs();
  249. int isnan(), isfinite();
  250. static double stirf();
  251. double lgam();
  252. #endif
  253. #ifdef INFINITIES
  254. extern double INFINITY;
  255. #endif
  256. #ifdef NANS
  257. extern double NAN;
  258. #endif
  259. /* Gamma function computed by Stirling's formula.
  260. * The polynomial STIR is valid for 33 <= x <= 172.
  261. */
  262. static double stirf(x) double x;
  263. {
  264. double y, w, v;
  265. w = 1.0 / x;
  266. w = 1.0 + w * polevl(w, STIR, 4);
  267. y = exp(x);
  268. if (x > MAXSTIR) { /* Avoid overflow in pow() */
  269. v = pow(x, 0.5 * x - 0.25);
  270. y = v * (v / y);
  271. } else {
  272. y = pow(x, x - 0.5) / y;
  273. }
  274. y = SQTPI * y * w;
  275. return (y);
  276. }
  277. double gamma(x) double x;
  278. {
  279. double p, q, z;
  280. int i;
  281. sgngam = 1;
  282. #ifdef NANS
  283. if (isnan(x))
  284. return (x);
  285. #endif
  286. #ifdef INFINITIES
  287. #ifdef NANS
  288. if (x == INFINITY)
  289. return (x);
  290. if (x == -INFINITY)
  291. return (NAN);
  292. #else
  293. if (!isfinite(x))
  294. return (x);
  295. #endif
  296. #endif
  297. q = fabs(x);
  298. if (q > 33.0) {
  299. if (x < 0.0) {
  300. p = floor(q);
  301. if (p == q) {
  302. #ifdef NANS
  303. gamnan:
  304. mtherr("gamma", DOMAIN);
  305. return (NAN);
  306. #else
  307. goto goverf;
  308. #endif
  309. }
  310. i = p;
  311. if ((i & 1) == 0)
  312. sgngam = -1;
  313. z = q - p;
  314. if (z > 0.5) {
  315. p += 1.0;
  316. z = q - p;
  317. }
  318. z = q * sin(PI * z);
  319. if (z == 0.0) {
  320. #ifdef INFINITIES
  321. return (sgngam * INFINITY);
  322. #else
  323. goverf:
  324. mtherr("gamma", OVERFLOW);
  325. return (sgngam * MAXNUM);
  326. #endif
  327. }
  328. z = fabs(z);
  329. z = PI / (z * stirf(q));
  330. } else {
  331. z = stirf(x);
  332. }
  333. return (sgngam * z);
  334. }
  335. z = 1.0;
  336. while (x >= 3.0) {
  337. x -= 1.0;
  338. z *= x;
  339. }
  340. while (x < 0.0) {
  341. if (x > -1.E-9)
  342. goto small;
  343. z /= x;
  344. x += 1.0;
  345. }
  346. while (x < 2.0) {
  347. if (x < 1.e-9)
  348. goto small;
  349. z /= x;
  350. x += 1.0;
  351. }
  352. if (x == 2.0)
  353. return (z);
  354. x -= 2.0;
  355. p = polevl(x, P, 6);
  356. q = polevl(x, Q, 7);
  357. return (z * p / q);
  358. small:
  359. if (x == 0.0) {
  360. #ifdef INFINITIES
  361. #ifdef NANS
  362. goto gamnan;
  363. #else
  364. return (INFINITY);
  365. #endif
  366. #else
  367. mtherr("gamma", SING);
  368. return (MAXNUM);
  369. #endif
  370. } else
  371. return (z / ((1.0 + 0.5772156649015329 * x) * x));
  372. }
  373. /* A[]: Stirling's formula expansion of log gamma
  374. * B[], C[]: log gamma function between 2 and 3
  375. */
  376. #ifdef UNK
  377. static double A[] = {8.11614167470508450300E-4, -5.95061904284301438324E-4,
  378. 7.93650340457716943945E-4, -2.77777777730099687205E-3,
  379. 8.33333333333331927722E-2};
  380. static double B[] = {-1.37825152569120859100E3, -3.88016315134637840924E4,
  381. -3.31612992738871184744E5, -1.16237097492762307383E6,
  382. -1.72173700820839662146E6, -8.53555664245765465627E5};
  383. static double C[] = {
  384. /* 1.00000000000000000000E0, */
  385. -3.51815701436523470549E2, -1.70642106651881159223E4,
  386. -2.20528590553854454839E5, -1.13933444367982507207E6,
  387. -2.53252307177582951285E6, -2.01889141433532773231E6};
  388. /* log( sqrt( 2*pi ) ) */
  389. static double LS2PI = 0.91893853320467274178;
  390. #define MAXLGM 2.556348e305
  391. #endif
  392. #ifdef DEC
  393. static unsigned short A[] = {0035524, 0141201, 0034633, 0031405, 0135433,
  394. 0176755, 0126007, 0045030, 0035520, 0006371,
  395. 0003342, 0172730, 0136066, 0005540, 0132605,
  396. 0026407, 0037252, 0125252, 0125252, 0125132};
  397. static unsigned short B[] = {
  398. 0142654, 0044014, 0077633, 0035410, 0144027, 0110641, 0125335, 0144760,
  399. 0144641, 0165637, 0142204, 0047447, 0145215, 0162027, 0146246, 0155211,
  400. 0145322, 0026110, 0010317, 0110130, 0145120, 0061472, 0120300, 0025363};
  401. static unsigned short C[] = {
  402. /*0040200,0000000,0000000,0000000*/
  403. 0142257, 0164150, 0163630, 0112622, 0143605, 0050153, 0156116, 0135272,
  404. 0144527, 0056045, 0145642, 0062332, 0145213, 0012063, 0106250, 0001025,
  405. 0145432, 0111254, 0044577, 0115142, 0145366, 0071133, 0050217, 0005122};
  406. /* log( sqrt( 2*pi ) ) */
  407. static unsigned short LS2P[] = {
  408. 040153,
  409. 037616,
  410. 041445,
  411. 0172645,
  412. };
  413. #define LS2PI *(double *)LS2P
  414. #define MAXLGM 2.035093e36
  415. #endif
  416. #ifdef IBMPC
  417. static unsigned short A[] = {0x6661, 0x2733, 0x9850, 0x3f4a, 0xe943,
  418. 0xb580, 0x7fbd, 0xbf43, 0x5ebb, 0x20dc,
  419. 0x019f, 0x3f4a, 0xa5a1, 0x16b0, 0xc16c,
  420. 0xbf66, 0x554b, 0x5555, 0x5555, 0x3fb5};
  421. static unsigned short B[] = {0x6761, 0x8ff3, 0x8901, 0xc095, 0xb93e, 0x355b,
  422. 0xf234, 0xc0e2, 0x89e5, 0xf890, 0x3d73, 0xc114,
  423. 0xdb51, 0xf994, 0xbc82, 0xc131, 0xf20b, 0x0219,
  424. 0x4589, 0xc13a, 0x055e, 0x5418, 0x0c67, 0xc12a};
  425. static unsigned short C[] = {
  426. /*0x0000,0x0000,0x0000,0x3ff0,*/
  427. 0x12b2, 0x1cf3, 0xfd0d, 0xc075, 0xd757, 0x7b89, 0xaa0d, 0xc0d0,
  428. 0x4c9b, 0xb974, 0xeb84, 0xc10a, 0x0043, 0x7195, 0x6286, 0xc131,
  429. 0xf34c, 0x892f, 0x5255, 0xc143, 0xe14a, 0x6a11, 0xce4b, 0xc13e};
  430. /* log( sqrt( 2*pi ) ) */
  431. static unsigned short LS2P[] = {0xbeb5, 0xc864, 0x67f1, 0x3fed};
  432. #define LS2PI *(double *)LS2P
  433. #define MAXLGM 2.556348e305
  434. #endif
  435. #ifdef MIEEE
  436. static unsigned short A[] = {0x3f4a, 0x9850, 0x2733, 0x6661, 0xbf43,
  437. 0x7fbd, 0xb580, 0xe943, 0x3f4a, 0x019f,
  438. 0x20dc, 0x5ebb, 0xbf66, 0xc16c, 0x16b0,
  439. 0xa5a1, 0x3fb5, 0x5555, 0x5555, 0x554b};
  440. static unsigned short B[] = {0xc095, 0x8901, 0x8ff3, 0x6761, 0xc0e2, 0xf234,
  441. 0x355b, 0xb93e, 0xc114, 0x3d73, 0xf890, 0x89e5,
  442. 0xc131, 0xbc82, 0xf994, 0xdb51, 0xc13a, 0x4589,
  443. 0x0219, 0xf20b, 0xc12a, 0x0c67, 0x5418, 0x055e};
  444. static unsigned short C[] = {0xc075, 0xfd0d, 0x1cf3, 0x12b2, 0xc0d0, 0xaa0d,
  445. 0x7b89, 0xd757, 0xc10a, 0xeb84, 0xb974, 0x4c9b,
  446. 0xc131, 0x6286, 0x7195, 0x0043, 0xc143, 0x5255,
  447. 0x892f, 0xf34c, 0xc13e, 0xce4b, 0x6a11, 0xe14a};
  448. /* log( sqrt( 2*pi ) ) */
  449. static unsigned short LS2P[] = {0x3fed, 0x67f1, 0xc864, 0xbeb5};
  450. #define LS2PI *(double *)LS2P
  451. #define MAXLGM 2.556348e305
  452. #endif
  453. /* Logarithm of gamma function */
  454. double lgam(x) double x;
  455. {
  456. double p, q, u, w, z;
  457. int i;
  458. sgngam = 1;
  459. #ifdef NANS
  460. if (isnan(x))
  461. return (x);
  462. #endif
  463. #ifdef INFINITIES
  464. if (!isfinite(x))
  465. return (INFINITY);
  466. #endif
  467. if (x < -34.0) {
  468. q = -x;
  469. w = lgam(q); /* note this modifies sgngam! */
  470. p = floor(q);
  471. if (p == q) {
  472. lgsing:
  473. #ifdef INFINITIES
  474. mtherr("lgam", SING);
  475. return (INFINITY);
  476. #else
  477. goto loverf;
  478. #endif
  479. }
  480. i = p;
  481. if ((i & 1) == 0)
  482. sgngam = -1;
  483. else
  484. sgngam = 1;
  485. z = q - p;
  486. if (z > 0.5) {
  487. p += 1.0;
  488. z = p - q;
  489. }
  490. z = q * sin(PI * z);
  491. if (z == 0.0)
  492. goto lgsing;
  493. /* z = log(PI) - log( z ) - w;*/
  494. z = LOGPI - log(z) - w;
  495. return (z);
  496. }
  497. if (x < 13.0) {
  498. z = 1.0;
  499. p = 0.0;
  500. u = x;
  501. while (u >= 3.0) {
  502. p -= 1.0;
  503. u = x + p;
  504. z *= u;
  505. }
  506. while (u < 2.0) {
  507. if (u == 0.0)
  508. goto lgsing;
  509. z /= u;
  510. p += 1.0;
  511. u = x + p;
  512. }
  513. if (z < 0.0) {
  514. sgngam = -1;
  515. z = -z;
  516. } else
  517. sgngam = 1;
  518. if (u == 2.0)
  519. return (log(z));
  520. p -= 2.0;
  521. x = x + p;
  522. p = x * polevl(x, B, 5) / p1evl(x, C, 6);
  523. return (log(z) + p);
  524. }
  525. if (x > MAXLGM) {
  526. #ifdef INFINITIES
  527. return (sgngam * INFINITY);
  528. #else
  529. loverf:
  530. mtherr("lgam", OVERFLOW);
  531. return (sgngam * MAXNUM);
  532. #endif
  533. }
  534. q = (x - 0.5) * log(x) - x + LS2PI;
  535. if (x > 1.0e8)
  536. return (q);
  537. p = 1.0 / (x * x);
  538. if (x >= 1000.0)
  539. q += ((7.9365079365079365079365e-4 * p - 2.7777777777777777777778e-3) * p +
  540. 0.0833333333333333333333) /
  541. x;
  542. else
  543. q += polevl(p, A, 4) / x;
  544. return (q);
  545. }