Skip to content

Commit db57b89

Browse files
authored
add erf(x,y) (#223)
1 parent 91026f3 commit db57b89

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SpecialFunctions"
22
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
3-
version = "0.11.0"
3+
version = "0.11.1"
44

55
[deps]
66
OpenSpecFun_jll = "efe28fd5-8261-553b-a9e1-b2916fc3738e"

src/erf.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ See also: [`erfc(x)`](@ref SpecialFunctions.erfc), [`erfcx(x)`](@ref SpecialFunc
6464
"""
6565
erf
6666

67+
@doc raw"""
68+
erf(x, y)
69+
70+
Compute the difference `erf(y) - erf(x)`, in a numerically sound way (only for real arguments).
71+
"""
72+
function erf(x::Real, y::Real)
73+
if 0 x && 0 y
74+
erfc(x) - erfc(y)
75+
elseif x 0 && y 0
76+
erfc(-y) - erfc(-x)
77+
else
78+
erf(y) - erf(x)
79+
end
80+
end
81+
6782
@doc raw"""
6883
erfc(x)
6984

test/erf.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@
131131
@test erfinv(one(Int)) == erfinv(1.0)
132132
@test erfcinv(one(Int)) == erfcinv(1.0)
133133
end
134+
135+
@testset "two args version" begin
136+
@test erf(10, 11) 2.08848758232167861905709161e-45
137+
@test erf(11, 10) -2.08848758232167861905709161e-45
138+
@test erf(-11, -10) 2.08848758232167861905709161e-45
139+
@test erf(-1, 1) 1.68540158589942973868244127017
140+
end
134141
end

0 commit comments

Comments
 (0)