Skip to content

Commit

Permalink
erf(x,y)
Browse files Browse the repository at this point in the history
  • Loading branch information
cossio committed May 13, 2020
1 parent 91026f3 commit d8f3dd2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/erf.jl
Expand Up @@ -64,6 +64,21 @@ See also: [`erfc(x)`](@ref SpecialFunctions.erfc), [`erfcx(x)`](@ref SpecialFunc
"""
erf

@doc raw"""
erf(x, y)
Compute the difference `erf(y) - erf(x)`, in an numerically sound way (only for real arguments).
"""
function erf(x::Real, y::Real)
if 0 x && 0 y
erfc(x) - erfc(y)
elseif x 0 && y 0
erfc(-y) - erfc(-x)
else
erf(y) - erf(x)
end
end

@doc raw"""
erfc(x)
Expand Down
7 changes: 7 additions & 0 deletions test/erf.jl
Expand Up @@ -131,4 +131,11 @@
@test erfinv(one(Int)) == erfinv(1.0)
@test erfcinv(one(Int)) == erfcinv(1.0)
end

@testset "two args version" begin
@test erf(10, 11) 2.08848758232167861905709161e-45
@test erf(11, 10) -2.08848758232167861905709161e-45
@test erf(-11, -10) 2.08848758232167861905709161e-45
@test erf(-1, 1) 1.68540158589942973868244127017
end
end

0 comments on commit d8f3dd2

Please sign in to comment.