1010
1111#define N 8
1212
13- #define B0 1.0 /* Bernoulli numbers */
14- #define B1 (-1.0 / 2.0)
15- #define B2 ( 1.0 / 6.0)
16- #define B4 (-1.0 / 30.0)
17- #define B6 ( 1.0 / 42.0)
18- #define B8 (-1.0 / 30.0)
19- #define B10 ( 5.0 / 66.0)
20- #define B12 (-691.0 / 2730.0)
21- #define B14 ( 7.0 / 6.0)
22- #define B16 (-3617.0 / 510.0)
13+ /* Bernoulli numbers */
14+ #define B0 1.0f
15+ #define B1 ( -1.0f / 2.0f)
16+ #define B2 ( 1.0f / 6.0f)
17+ #define B4 ( -1.0f / 30.0f)
18+ #define B6 ( 1.0f / 42.0f)
19+ #define B8 ( -1.0f / 30.0f)
20+ #define B10 ( 5.0f / 66.0f)
21+ #define B12 ( -691.0f / 2730.0f)
22+ #define B14 ( 7.0f / 6.0f)
23+ #define B16 (-3617.0f / 510.0f)
2324
25+ #define ln_pi_div_2 0.91893853320467274178032973640562f
26+
27+ /**
28+ * @remarks Minimum relative precision of:
29+ * 2^-16.97 at +3.205794811e+00 with ideal logf (x > 3.0f)
30+ * 2^-16.71 at +2.940585591e-39 with ideal logf (x > 0.0f && x < 0.5f)
31+ * 2^-13.68 at +1.591955781e+00 with ideal logf (x > 1.25f && x < 1.75f)
32+ * @note input values 0.5f - 3.0f have very low precision
33+ */
2434float lgammaf (float x ) { /* the natural logarithm of the Gamma function. */
2535 float v , w ;
26- v = 1.0 ;
36+ v = 1.0f ;
2737
2838 /**
2939 * This loop will take forever to terminate if `x < -100.0f`, so we have a
@@ -38,12 +48,12 @@ float lgammaf(float x) { /* the natural logarithm of the Gamma function. */
3848 v *= x ;
3949 x ++ ;
4050 }
41- w = 1.0 / (x * x );
42- return ((((((((B16 / (16.0 * 15.0 )) * w + (B14 / (14.0 * 13.0 ))) * w
43- + (B12 / (12.0 * 11.0 ))) * w + (B10 / (10.0 * 9.0 ))) * w
44- + (B8 / ( 8.0 * 7.0 ))) * w + (B6 / ( 6.0 * 5.0 ))) * w
45- + (B4 / ( 4.0 * 3.0 ))) * w + (B2 / ( 2.0 * 1.0 ))) / x
46- + 0.5 * ( float ) M_LOG_2M_PI - logf (v ) - x + (x - 0.5 ) * logf (x );
51+ w = 1.0f / (x * x );
52+ return ((((((((B16 / (16.0f * 15.0f )) * w + (B14 / (14.0f * 13.0f ))) * w
53+ + (B12 / (12.0f * 11.0f ))) * w + (B10 / (10.0f * 9.0f ))) * w
54+ + (B8 / ( 8.0f * 7.0f ))) * w + (B6 / ( 6.0f * 5.0f ))) * w
55+ + (B4 / ( 4.0f * 3.0f ))) * w + (B2 / ( 2.0f * 1.0f ))) / x
56+ + ln_pi_div_2 - logf (v ) - x + (x - 0.5f ) * logf (x );
4757}
4858
4959double lgamma (double ) __attribute__((alias ("lgammaf" )));
0 commit comments