Skip to content

Commit b5117a6

Browse files
committed
Update FermiDiracOneHalfTeSCA
Replace evaluations of log(1+x) with log1p(x). In the code this occurs twice. In the old version, trickery in the first branch catched the case when 1+x == 1 with a test if w==0. We had this discussion before, the trick came from JuliaDiff/ForwardDiff.jl#481 This does not work anymore with JuliaDiff/ForwardDiff.jl#481 This PR (unfortunately) is now in v0.10.33 of ForwardDiff.jl. There is a discussion going on that this should have been 0.11, i.e. marked as a breaking change. It did break Example 103, the PR fixes this.
1 parent bb6e49e commit b5117a6

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/ct_distributions.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
using ForwardDiff
32

43
"""
@@ -65,24 +64,23 @@ $(TYPEDSIGNATURES)
6564
6665
The incomplete Fermi-Dirac integral of order 1/2, implemented according to the software
6766
package TeSCA, see https://wias-berlin.de/software/index.jsp?lang=1&id=TeSCA.
67+
68+
Modified to use log1p(x)=log(1+x).
6869
"""
6970
function FermiDiracOneHalfTeSCA(x::Real)
7071
if x < 1.6107
71-
ex = exp(x)
72-
y = 1+ex
73-
w = y-1
74-
z = w==0 ? ex : ex*log(y)/w
72+
z=log1p(exp(x))
7573
return ( 1 + 0.16 * z ) * z
7674
elseif 1.6107 <= x <= 344.7
77-
z = log( 1 + exp( x^(3/4)) )
78-
return 0.3258 - 0.0321 * z + 0.7523 * z^2
75+
z = log1p(exp( x^(3/4)) )
76+
return 0.3258 - (0.0321 - 0.7523 * z ) * z
7977
else
8078
z = x^(3/4)
81-
return 0.3258 - 0.0321 * z + 0.7523 * z^2
79+
return 0.3258 - (0.0321 - 0.7523 * z ) * z
8280
end
83-
8481
end
8582

83+
8684
"""
8785
$(TYPEDSIGNATURES)
8886

0 commit comments

Comments
 (0)