Skip to content

Commit

Permalink
Finish refactoring setprecision, setrounding etc. Correct root_findin…
Browse files Browse the repository at this point in the history
…g tests
  • Loading branch information
dpsanders committed Apr 7, 2016
1 parent 4f335b3 commit 83301ca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ julia> @interval(pi)

To check which mode is currently set, use
```julia
julia> precision(Interval)()
julia> precision(Interval)
(Float64,-1)
```
The result is a tuple of the type (currently `Float64` or `BigFloat`) and the precision (relevant only for `BigFloat`s).
Expand Down
6 changes: 3 additions & 3 deletions src/intervals/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ that this interval is an exception to the fact that the lower bound is
larger than the upper one."""
emptyinterval{T<:Real}(::Type{T}) = Interval{T}(Inf, -Inf)
emptyinterval{T<:Real}(x::Interval{T}) = emptyinterval(T)
emptyinterval() = emptyinterval(precision(Interval)()[1])
emptyinterval() = emptyinterval(precision(Interval)[1])
const= emptyinterval(Float64)

isempty(x::Interval) = x.lo == Inf && x.hi == -Inf
Expand All @@ -19,7 +19,7 @@ const ∞ = Inf
doc"""`entireinterval`s represent the whole Real line: [-∞, ∞]."""
entireinterval{T<:Real}(::Type{T}) = Interval{T}(-Inf, Inf)
entireinterval{T<:Real}(x::Interval{T}) = entireinterval(T)
entireinterval() = entireinterval(precision(Interval)()[1])
entireinterval() = entireinterval(precision(Interval)[1])

isentire(x::Interval) = x.lo == -Inf && x.hi == Inf
isunbounded(x::Interval) = x.lo == -Inf || x.hi == Inf
Expand All @@ -29,7 +29,7 @@ isunbounded(x::Interval) = x.lo == -Inf || x.hi == Inf
doc"""`NaI` not-an-interval: [NaN, NaN]."""
nai{T<:Real}(::Type{T}) = Interval{T}(NaN, NaN)
nai{T<:Real}(x::Interval{T}) = nai(T)
nai() = nai(precision(Interval)()[1])
nai() = nai(precision(Interval)[1])

isnai(x::Interval) = isnan(x.lo) || isnan(x.hi)

Expand Down
8 changes: 4 additions & 4 deletions test/interval_tests/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ b = @interval(0.9, 2.0)
c = @interval(0.25, 4.0)

facts("Consistency tests") do

@fact isa( @interval(1,2), Interval ) --> true
@fact isa( @interval(0.1), Interval ) --> true
@fact isa( zero(b), Interval ) --> true
Expand Down Expand Up @@ -249,10 +249,10 @@ end

facts("Precision tests") do
setprecision(Interval, 100)
@fact precision(Interval)() == (BigFloat, 100) --> true
@fact precision(Interval) == (BigFloat, 100) --> true

setprecision(Interval, Float64)
@fact precision(Interval)() == (Float64, 100) --> true
@fact precision(Interval) == (Float64, 100) --> true

a = @interval(0.1, 0.3)

Expand All @@ -262,7 +262,7 @@ facts("Precision tests") do

@fact b a --> true

@fact precision(Interval)() == (Float64, 100) --> true
@fact precision(Interval) == (Float64, 100) --> true

end

Expand Down
23 changes: 10 additions & 13 deletions test/root_finding_tests/root_finding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ function generate_wilkinson(n)#, T=BigFloat) # SLOW
end


setprecision(Interval, BigFloat)
big_pi = @interval(pi)

setprecision(Interval, Float64)
float_pi = @interval(pi)


setprecision(Interval, 10000)
big_pi = @interval(pi)
# Using precision "only" 256 leads to overestimation of the true roots for `cos`
# i.e the Newton method gives more accurate results!

setprecision(Interval, 10000)

big_pi = @interval(pi)
half_pi = big_pi / 2
three_halves_pi = 3*big_pi/2

Expand All @@ -53,12 +48,14 @@ function_list = [


facts("Testing root finding") do
for interval_precision in (:wide, :narrow)
context("Interval precision: $interval_precision") do

for precision_type in ( (BigFloat,53), (BigFloat,256), (Float64, 64) ) #, (BigFloat,1024) )#, (Float64, -1)
context("Precision: $precision_type") do
setprecision(Interval, precision_type)
for rounding_type in (:wide, :narrow)
context("Interval rounding: $rounding_type") do
setrounding(Interval, rounding_type)

for prec in ( (BigFloat,53), (BigFloat,256), (Float64,64) )
context("Precision: $prec") do
setprecision(Interval, prec)

for method in (newton, krawczyk)
context("Method $method") do
Expand All @@ -85,7 +82,7 @@ facts("Testing root finding") do
for i in 1:length(roots)
root = roots[i]

@fact isa(root, Root{precision_type[1]}) --> true
@fact isa(root, Root{prec[1]}) --> true
@fact is_unique(root) --> true
@fact true_roots[i] root.interval --> true
end
Expand Down

0 comments on commit 83301ca

Please sign in to comment.