Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert dotdot #97

Merged
merged 8 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/intervals/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ promote_rule(::Type{BigFloat}, ::Type{Interval{T}}) where T<:Real =
convert(::Type{Interval{T}}, x::AbstractString) where T<:AbstractFloat =
parse(Interval{T}, x)

convert(::Type{Interval}, x::AbstractString) = convert(Interval{Float64}, x)

function convert(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:Real}
isinf(x) && return wideinterval(T(x))

Expand All @@ -26,7 +28,7 @@ function convert(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:Real}
# use @round_up and @round_down here?
end

function convert(::Type{Interval{T}}, x::Float64) where T<:AbstractFloat
function convert(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:AbstractFloat}
isinf(x) && return wideinterval(x)#Interval{T}(prevfloat(T(x)), nextfloat(T(x)))
# isinf(x) && return Interval{T}(prevfloat(x), nextfloat(x))

Expand Down
12 changes: 6 additions & 6 deletions src/intervals/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ include("hyperbolic.jl")

# Syntax for intervals

# a..b = Interval(convert(Interval, a).lo, convert(Interval, b).hi)
a..b = interval(convert(Interval, a).lo, convert(Interval, b).hi)

..(a::Integer, b::Integer) = interval(a, b)
..(a::Integer, b::Real) = interval(a, nextfloat(float(b)))
..(a::Real, b::Integer) = interval(prevfloat(float(a)), b)

..(a::Real, b::Real) = interval(prevfloat(float(a)), nextfloat(float(b)))
# ..(a::Integer, b::Integer) = interval(a, b)
# ..(a::Integer, b::Real) = interval(a, nextfloat(float(b)))
# ..(a::Real, b::Integer) = interval(prevfloat(float(a)), b)
#
# ..(a::Real, b::Real) = interval(prevfloat(float(a)), nextfloat(float(b)))

macro I_str(ex) # I"[3,4]"
@interval(ex)
Expand Down
8 changes: 3 additions & 5 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ function parse(::Type{Interval{T}}, s::AbstractString) where T
return a ± b
end

expr = parse(s)
a = parse(T, s, RoundDown)
b = parse(T, s, RoundUp)

# after removing support for Julia 0.4, can simplify
# make_interval to just accept two expressions
return Interval(a, b)

val = make_interval(T, expr, [expr]) # use tryparse?
return eval(val)
end

# match string of form [a, b]_dec:
Expand Down
1 change: 0 additions & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
FactCheck 0.3
Polynomials 0.1.0
4 changes: 2 additions & 2 deletions test/display_tests/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setprecision(Interval, Float64)
setformat(sigfigs=20)

@test string(a) == "[1, 2]"
@test string(b) == "[-1.1000000000000003109, 1.3000000000000002665]"
@test string(b) == "[-1.1000000000000000889, 1.3000000000000000445]"
@test string(c) == "[3.1415926535897931159, 3.141592653589793116]"
@test string(d) == "[3.1415926535897931159, 3.1415926535897935601]"
end
Expand All @@ -43,7 +43,7 @@ setprecision(Interval, Float64)
setformat(:full)

@test string(a) == "Interval(1.0, 2.0)"
@test string(b) == "Interval(-1.1000000000000003, 1.3000000000000003)"
@test string(b) == "Interval(-1.1, 1.3)"
@test string(c) == "Interval(3.141592653589793, 3.141592653589793)"
@test string(d) == "Interval(3.141592653589793, 3.1415926535897936)"
end
Expand Down
17 changes: 9 additions & 8 deletions test/interval_tests/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ using Base.Test
@test convert(Interval, BigInt(1)) == Interval(BigInt(1))
@test convert(Interval, 1//10) == @interval(1//10)
@test convert(Interval, 0.1) == Interval(0.09999999999999999, 0.1)
@test convert(Interval, BigFloat(0.1)) == Interval(big(0.1))

@test convert(Interval, big"0.1") == big"0.1"..big"0.1"

@test convert(Interval{Rational{Int}}, 0.1) == Interval(1//10)
# @test convert(Interval{Rational{BigInt}}, pi) == Interval{Rational{BigInt}}(pi)
Expand All @@ -75,7 +74,7 @@ using Base.Test
@test promote(Interval(2//1,3//1), Interval(1, 2)) ==
(Interval(2.0,3.0), Interval(1.0,2.0))
@test promote(Interval(1.5), parse(BigFloat, "2.1")) ==
(Interval(BigFloat(1.5)), Interval(BigFloat(2.1)))
(Interval(BigFloat(1.5)), big"2.1"..big"2.1")
@test promote(Interval(1.0), pi) == (Interval(1.0), @interval(pi))

# Constructors from the macros @interval, @floatinterval @biginterval
Expand Down Expand Up @@ -173,7 +172,9 @@ end

@test @floatinterval(123412341234123412341241234) == Interval(1.234123412341234e26, 1.2341234123412342e26)
@test @interval(big"3") == @floatinterval(3)
@test @floatinterval(big"1e10000") == Interval(1.7976931348623157e308, ∞)


@test_skip @floatinterval(big"1e10000") == Interval(1.7976931348623157e308, ∞)

a = big(10)^10000
@test @floatinterval(a) == Interval(1.7976931348623157e308, ∞)
Expand Down Expand Up @@ -209,12 +210,12 @@ end
setprecision(Interval, Float64)

@test 3 ± 1 == Interval(2.0, 4.0)
@test 3 ± 0.5 == Interval(2.4999999999999996, 3.5000000000000004)
@test 3 ± 0.1 == Interval(2.8999999999999995, 3.1000000000000005)
@test 0.5 ± 1 == Interval(-0.5000000000000001, 1.5000000000000002)
@test 3 ± 0.5 == 2.5..3.5
@test 3 ± 0.1 == 2.9..3.1
@test 0.5 ± 1 == -0.5..1.5

# issue 172:
@test_throws MethodError a = (1..1) ± 1
@test (1..1) ± 1 == 0..2

end

Expand Down
6 changes: 3 additions & 3 deletions test/interval_tests/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ setprecision(128)
@test parse(Interval{Float64}, "[Empty]") == emptyinterval(Float64)
@test parse(Interval{BigFloat}, "[Empty]") == emptyinterval(BigFloat)

@test parse(Interval{Float64}, "3 ± 4") == Interval(-1.0000000000000002, 7.000000000000001)
@test parse(Interval{Float64}, "0.2 ± 0.1") == Interval(0.09999999999999999, 0.3000000000000001)
@test parse(Interval{BigFloat}, "0.2 ± 0.1") == Interval(big"9.999999999999999999999999999999999999971e-02", big"3.000000000000000000000000000000000000021e-01")
@test parse(Interval{Float64}, "3 ± 4") == (-1)..7
@test parse(Interval{Float64}, "0.2 ± 0.1") == 0.1..0.3
@test parse(Interval{BigFloat}, "0.2 ± 0.1") == big"0.2" ± big"0.1"
end

@testset "Parse string to DecoratedInterval" begin
Expand Down