|
89 | 89 | function _lgamma_r(x::Float64)
|
90 | 90 | u = reinterpret(UInt64, x)
|
91 | 91 | hx = u >>> 32 % Int32
|
92 |
| - lx = u % Int32 |
| 92 | + lx = u % UInt32 |
93 | 93 |
|
94 | 94 | #= purge off +-inf, NaN, +-0, tiny and negative arguments =#
|
95 | 95 | signgamp = Int32(1)
|
96 | 96 | ix = hx & 0x7fffffff
|
97 |
| - ix ≥ 0x7ff00000 && return typemax(x), signgamp |
98 |
| - ix | lx == 0x00000000 && return typemax(x), signgamp |
| 97 | + ix ≥ 0x7ff00000 && return Inf, signgamp |
| 98 | + ix | lx == 0x00000000 && return Inf, signgamp |
99 | 99 | if ix < 0x3b900000 #= |x|<2**-70, return -log(|x|) =#
|
100 |
| - if hx < 0 # x < 0 |
| 100 | + if hx < Int32(0) |
101 | 101 | signgamp = Int32(-1)
|
102 | 102 | return -log(-x), signgamp
|
103 | 103 | else
|
104 | 104 | return -log(x), signgamp
|
105 | 105 | end
|
106 | 106 | end
|
107 |
| - if hx < 0 |
108 |
| - # ix ≥ 0x43300000 && return typemax(x), signgamp #= |x|≥2^52, must be -integer =# |
| 107 | + if hx < Int32(0) |
| 108 | + # ix ≥ 0x43300000 && return Inf, signgamp #= |x|>=2**52, must be -integer =# |
109 | 109 | t = sinpi(x)
|
110 |
| - iszero(t) && return typemax(x), signgamp #= -integer =# |
| 110 | + iszero(t) && return Inf, signgamp #= -integer =# |
111 | 111 | nadj = log(π / abs(t * x))
|
112 | 112 | if t < 0.0; signgamp = Int32(-1); end
|
113 | 113 | x = -x
|
114 | 114 | end
|
115 |
| - if ix ≤ 0x40000000 #= for x < 2.0 =# |
116 |
| - ipart = round(x, RoundToZero) |
117 |
| - fpart = x - ipart |
118 |
| - if iszero(fpart) |
| 115 | + if ix ≤ 0x40000000 #= for 1.0 ≤ x ≤ 2.0 =# |
| 116 | + i = round(x, RoundToZero) |
| 117 | + f = x - i |
| 118 | + if f == 0.0 #= purge off 1 and 2 =# |
119 | 119 | return 0.0, signgamp
|
120 |
| - elseif isone(ipart) |
| 120 | + elseif i == 1.0 |
121 | 121 | r = 0.0
|
122 | 122 | c = 1.0
|
123 | 123 | else
|
124 | 124 | r = -log(x)
|
125 | 125 | c = 0.0
|
126 | 126 | end
|
127 |
| - if fpart ≥ 0.7315998077392578 |
| 127 | + if f ≥ 0.7315998077392578 |
128 | 128 | y = 1.0 + c - x
|
129 | 129 | z = y * y
|
130 | 130 | p1 = evalpoly(z, (7.72156649015328655494e-02, 6.73523010531292681824e-02, 7.38555086081402883957e-03, 1.19270763183362067845e-03, 2.20862790713908385557e-04, 2.52144565451257326939e-05))
|
131 | 131 | p2 = z * evalpoly(z, (3.22467033424113591611e-01, 2.05808084325167332806e-02, 2.89051383673415629091e-03, 5.10069792153511336608e-04, 1.08011567247583939954e-04, 4.48640949618915160150e-05))
|
132 | 132 | p = muladd(p1, y, p2)
|
133 | 133 | r += muladd(y, -0.5, p)
|
134 |
| - elseif fpart ≥ 0.2316399812698364 # or, the lb? 0.2316322326660156 |
| 134 | + elseif f ≥ 0.2316399812698364 # or, the lb? 0.2316322326660156 |
135 | 135 | y = x - 0.46163214496836225 - c
|
136 | 136 | z = y * y
|
137 | 137 | w = z * y
|
@@ -168,7 +168,7 @@ function _lgamma_r(x::Float64)
|
168 | 168 | else #= 2^58 ≤ x ≤ Inf =#
|
169 | 169 | r = muladd(x, log(x), -x)
|
170 | 170 | end
|
171 |
| - if hx < 0 |
| 171 | + if hx < Int32(0) |
172 | 172 | r = nadj - r
|
173 | 173 | end
|
174 | 174 | return r, signgamp
|
|
0 commit comments