diff --git a/docs/usage.md b/docs/usage.md index 8da9ae7..03daff8 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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). diff --git a/src/intervals/special.jl b/src/intervals/special.jl index dab2c8d..32e981a 100644 --- a/src/intervals/special.jl +++ b/src/intervals/special.jl @@ -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 @@ -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 @@ -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) diff --git a/test/interval_tests/consistency.jl b/test/interval_tests/consistency.jl index 9aa1631..c6ebed0 100644 --- a/test/interval_tests/consistency.jl +++ b/test/interval_tests/consistency.jl @@ -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 @@ -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) @@ -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 diff --git a/test/root_finding_tests/root_finding.jl b/test/root_finding_tests/root_finding.jl index d6f5fbd..ce67b30 100644 --- a/test/root_finding_tests/root_finding.jl +++ b/test/root_finding_tests/root_finding.jl @@ -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 @@ -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 @@ -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