Skip to content

Commit afb03a3

Browse files
SebastianM-Cdpsanders
authored andcommitted
WIP: Add erf and erfc (#118)
* Add erf and erfc * Add test file * Add SpecialFunctions to REQUIRE * Fix Interval{Float64} case -Also fix line endings for test file * Add tests
1 parent a1a9e8c commit afb03a3

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ StaticArrays 0.5
44
FastRounding 0.0.4
55
AdjacentFloats 0.0.5
66
RecipesBase
7-
7+
SpecialFunctions

src/IntervalArithmetic.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import Base:
2929
isinteger, setdiff,
3030
parse
3131

32+
import SpecialFunctions:
33+
erf, erfc
34+
3235
export
3336
AbstractInterval, Interval,
3437
interval,

src/intervals/functions.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,24 @@ for f in (:log, :log2, :log10, :log1p)
266266

267267
end
268268
end
269+
270+
for f in (:erf, :erfc)
271+
@eval function($f)(x::BigFloat, r::RoundingMode)
272+
setrounding(BigFloat, r) do
273+
($f)(x)
274+
end
275+
end
276+
277+
@eval ($f)(a::Interval{Float64}) = convert(Interval{Float64}, ($f)(big53(a)))
278+
279+
end
280+
281+
function erf(a::Interval{T}) where T
282+
isempty(a) && return a
283+
@round( erf(a.lo), erf(a.hi) )
284+
end
285+
286+
function erfc(a::Interval{T}) where T
287+
isempty(a) && return a
288+
@round( erfc(a.hi), erfc(a.lo) )
289+
end

test/interval_tests/intervals.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include("consistency.jl")
55
include("numeric.jl")
66
include("trig.jl")
77
include("hyperbolic.jl")
8+
include("special_functions.jl")
89
include("non_BigFloat.jl")
910
include("linear_algebra.jl")
1011
include("loops.jl")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is part of the IntervalArithmetic.jl package; MIT licensed
2+
3+
using IntervalArithmetic
4+
using Base.Test
5+
6+
setprecision(Interval, 128)
7+
setprecision(Interval, Float64)
8+
9+
@testset "Special Functions tests" begin
10+
@test erf(emptyinterval()) == emptyinterval()
11+
@test erf(1..2) == Interval(0.8427007929497148, 0.9953222650189528)
12+
@test erf(@interval(0.5)) == Interval(5.2049987781304652e-01, 5.2049987781304663e-01)
13+
@test erf(0..0) == Interval(0.0, 0.0)
14+
@test erf(@biginterval(-1, 1)) Interval(-8.4270079294971489e-01, 8.4270079294971489e-01)
15+
16+
@test erfc(emptyinterval()) == emptyinterval()
17+
@test erfc(1..2) == Interval(0.004677734981047265, 0.15729920705028513)
18+
@test erfc(@interval(0.5)) == Interval(4.7950012218695343e-01, 4.7950012218695348e-01)
19+
@test erfc(0..0) == Interval(1.0, 1.0)
20+
@test erfc(@biginterval(-1, 1)) Interval(1.5729920705028511e-01, 1.842700792949715)
21+
end

0 commit comments

Comments
 (0)