Skip to content

Commit f27ecab

Browse files
Be more literal since Float64 and Float32 implementations are separate
1 parent 606190d commit f27ecab

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/e_lgamma_r.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,49 +89,49 @@
8989
function _lgamma_r(x::Float64)
9090
u = reinterpret(UInt64, x)
9191
hx = u >>> 32 % Int32
92-
lx = u % Int32
92+
lx = u % UInt32
9393

9494
#= purge off +-inf, NaN, +-0, tiny and negative arguments =#
9595
signgamp = Int32(1)
9696
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
9999
if ix < 0x3b900000 #= |x|<2**-70, return -log(|x|) =#
100-
if hx < 0 # x < 0
100+
if hx < Int32(0)
101101
signgamp = Int32(-1)
102102
return -log(-x), signgamp
103103
else
104104
return -log(x), signgamp
105105
end
106106
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 =#
109109
t = sinpi(x)
110-
iszero(t) && return typemax(x), signgamp #= -integer =#
110+
iszero(t) && return Inf, signgamp #= -integer =#
111111
nadj = log/ abs(t * x))
112112
if t < 0.0; signgamp = Int32(-1); end
113113
x = -x
114114
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 =#
119119
return 0.0, signgamp
120-
elseif isone(ipart)
120+
elseif i == 1.0
121121
r = 0.0
122122
c = 1.0
123123
else
124124
r = -log(x)
125125
c = 0.0
126126
end
127-
if fpart 0.7315998077392578
127+
if f 0.7315998077392578
128128
y = 1.0 + c - x
129129
z = y * y
130130
p1 = evalpoly(z, (7.72156649015328655494e-02, 6.73523010531292681824e-02, 7.38555086081402883957e-03, 1.19270763183362067845e-03, 2.20862790713908385557e-04, 2.52144565451257326939e-05))
131131
p2 = z * evalpoly(z, (3.22467033424113591611e-01, 2.05808084325167332806e-02, 2.89051383673415629091e-03, 5.10069792153511336608e-04, 1.08011567247583939954e-04, 4.48640949618915160150e-05))
132132
p = muladd(p1, y, p2)
133133
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
135135
y = x - 0.46163214496836225 - c
136136
z = y * y
137137
w = z * y
@@ -168,7 +168,7 @@ function _lgamma_r(x::Float64)
168168
else #= 2^58 ≤ x ≤ Inf =#
169169
r = muladd(x, log(x), -x)
170170
end
171-
if hx < 0
171+
if hx < Int32(0)
172172
r = nadj - r
173173
end
174174
return r, signgamp

0 commit comments

Comments
 (0)