Skip to content

Commit

Permalink
Solves #136 (#137)
Browse files Browse the repository at this point in the history
* Change a convert method, addressin Issue 136

This implements an idea of David to solve Issue 136; it does
solve it, but a test is now failing.

* Prevent case when rationalize(x) is zero, for non-zero x

* Add tests for intervals with small values
  • Loading branch information
lbenet authored and dpsanders committed May 21, 2016
1 parent 378e6c9 commit 2ad4986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/intervals/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ function convert{T<:AbstractFloat, S<:Real}(::Type{Interval{T}}, x::S)
end

function convert{T<:AbstractFloat}(::Type{Interval{T}}, x::Float64)
convert(Interval{T}, rationalize(x))
II = convert(Interval{T}, rationalize(x))
# This prevents that rationalize(x) returns a zero when x is very small
if x != zero(x) && II == zero(Interval{T})
II = Interval{T}(string(x))
end
II
end

function convert{T<:AbstractFloat}(::Type{Interval{T}}, x::Interval)
Expand Down
3 changes: 3 additions & 0 deletions test/interval_tests/numeric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ facts("Numeric tests") do
@fact Interval(0.0, 1.0)/Interval(0.0,1.0) --> Interval(0.0, Inf)
@fact Interval(-1.0, 1.0)/Interval(0.0,1.0) --> entireinterval(c)
@fact Interval(-1.0, 1.0)/Interval(-1.0,1.0) --> entireinterval(c)
a = @interval(1.e-20)
@fact a --> Interval(1.0e-20, 1.0000000000000001e-20)
@fact diam(a) --> eps(1.e-20)
end

facts("Power tests") do
Expand Down

0 comments on commit 2ad4986

Please sign in to comment.