Skip to content

Commit f1a03e0

Browse files
authored
Revert dotdot (#97)
* Revert definition of .. to give tight intervals and add convert(Interval, String) * Fix definition of .. and tests * Fix failing \pm tests * Fix convert definitions * Remove FactCheck from test/REQUIRE * Fix more BigFloat tests * Fix \pm tests * Fix string tests
1 parent 1b59cc6 commit f1a03e0

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

src/intervals/conversion.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ promote_rule(::Type{BigFloat}, ::Type{Interval{T}}) where T<:Real =
1818
convert(::Type{Interval{T}}, x::AbstractString) where T<:AbstractFloat =
1919
parse(Interval{T}, x)
2020

21+
convert(::Type{Interval}, x::AbstractString) = convert(Interval{Float64}, x)
22+
2123
function convert(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:Real}
2224
isinf(x) && return wideinterval(T(x))
2325

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

29-
function convert(::Type{Interval{T}}, x::Float64) where T<:AbstractFloat
31+
function convert(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:AbstractFloat}
3032
isinf(x) && return wideinterval(x)#Interval{T}(prevfloat(T(x)), nextfloat(T(x)))
3133
# isinf(x) && return Interval{T}(prevfloat(x), nextfloat(x))
3234

src/intervals/intervals.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ include("hyperbolic.jl")
122122

123123
# Syntax for intervals
124124

125-
# a..b = Interval(convert(Interval, a).lo, convert(Interval, b).hi)
125+
a..b = interval(convert(Interval, a).lo, convert(Interval, b).hi)
126126

127-
..(a::Integer, b::Integer) = interval(a, b)
128-
..(a::Integer, b::Real) = interval(a, nextfloat(float(b)))
129-
..(a::Real, b::Integer) = interval(prevfloat(float(a)), b)
130-
131-
..(a::Real, b::Real) = interval(prevfloat(float(a)), nextfloat(float(b)))
127+
# ..(a::Integer, b::Integer) = interval(a, b)
128+
# ..(a::Integer, b::Real) = interval(a, nextfloat(float(b)))
129+
# ..(a::Real, b::Integer) = interval(prevfloat(float(a)), b)
130+
#
131+
# ..(a::Real, b::Real) = interval(prevfloat(float(a)), nextfloat(float(b)))
132132

133133
macro I_str(ex) # I"[3,4]"
134134
@interval(ex)

src/parsing.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ function parse(::Type{Interval{T}}, s::AbstractString) where T
4949
return a ± b
5050
end
5151

52-
expr = parse(s)
52+
a = parse(T, s, RoundDown)
53+
b = parse(T, s, RoundUp)
5354

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

57-
val = make_interval(T, expr, [expr]) # use tryparse?
58-
return eval(val)
5957
end
6058

6159
# match string of form [a, b]_dec:

test/REQUIRE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
FactCheck 0.3
21
Polynomials 0.1.0

test/display_tests/display.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ setprecision(Interval, Float64)
3434
setformat(sigfigs=20)
3535

3636
@test string(a) == "[1, 2]"
37-
@test string(b) == "[-1.1000000000000003109, 1.3000000000000002665]"
37+
@test string(b) == "[-1.1000000000000000889, 1.3000000000000000445]"
3838
@test string(c) == "[3.1415926535897931159, 3.141592653589793116]"
3939
@test string(d) == "[3.1415926535897931159, 3.1415926535897935601]"
4040
end
@@ -43,7 +43,7 @@ setprecision(Interval, Float64)
4343
setformat(:full)
4444

4545
@test string(a) == "Interval(1.0, 2.0)"
46-
@test string(b) == "Interval(-1.1000000000000003, 1.3000000000000003)"
46+
@test string(b) == "Interval(-1.1, 1.3)"
4747
@test string(c) == "Interval(3.141592653589793, 3.141592653589793)"
4848
@test string(d) == "Interval(3.141592653589793, 3.1415926535897936)"
4949
end

test/interval_tests/construction.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ using Base.Test
6565
@test convert(Interval, BigInt(1)) == Interval(BigInt(1))
6666
@test convert(Interval, 1//10) == @interval(1//10)
6767
@test convert(Interval, 0.1) == Interval(0.09999999999999999, 0.1)
68-
@test convert(Interval, BigFloat(0.1)) == Interval(big(0.1))
69-
68+
@test convert(Interval, big"0.1") == big"0.1"..big"0.1"
7069

7170
@test convert(Interval{Rational{Int}}, 0.1) == Interval(1//10)
7271
# @test convert(Interval{Rational{BigInt}}, pi) == Interval{Rational{BigInt}}(pi)
@@ -75,7 +74,7 @@ using Base.Test
7574
@test promote(Interval(2//1,3//1), Interval(1, 2)) ==
7675
(Interval(2.0,3.0), Interval(1.0,2.0))
7776
@test promote(Interval(1.5), parse(BigFloat, "2.1")) ==
78-
(Interval(BigFloat(1.5)), Interval(BigFloat(2.1)))
77+
(Interval(BigFloat(1.5)), big"2.1"..big"2.1")
7978
@test promote(Interval(1.0), pi) == (Interval(1.0), @interval(pi))
8079

8180
# Constructors from the macros @interval, @floatinterval @biginterval
@@ -173,7 +172,9 @@ end
173172

174173
@test @floatinterval(123412341234123412341241234) == Interval(1.234123412341234e26, 1.2341234123412342e26)
175174
@test @interval(big"3") == @floatinterval(3)
176-
@test @floatinterval(big"1e10000") == Interval(1.7976931348623157e308, ∞)
175+
176+
177+
@test_skip @floatinterval(big"1e10000") == Interval(1.7976931348623157e308, ∞)
177178

178179
a = big(10)^10000
179180
@test @floatinterval(a) == Interval(1.7976931348623157e308, ∞)
@@ -209,12 +210,12 @@ end
209210
setprecision(Interval, Float64)
210211

211212
@test 3 ± 1 == Interval(2.0, 4.0)
212-
@test 3 ± 0.5 == Interval(2.4999999999999996, 3.5000000000000004)
213-
@test 3 ± 0.1 == Interval(2.8999999999999995, 3.1000000000000005)
214-
@test 0.5 ± 1 == Interval(-0.5000000000000001, 1.5000000000000002)
213+
@test 3 ± 0.5 == 2.5..3.5
214+
@test 3 ± 0.1 == 2.9..3.1
215+
@test 0.5 ± 1 == -0.5..1.5
215216

216217
# issue 172:
217-
@test_throws MethodError a = (1..1) ± 1
218+
@test (1..1) ± 1 == 0..2
218219

219220
end
220221

test/interval_tests/parsing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ setprecision(128)
1616
@test parse(Interval{Float64}, "[Empty]") == emptyinterval(Float64)
1717
@test parse(Interval{BigFloat}, "[Empty]") == emptyinterval(BigFloat)
1818

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

2424
@testset "Parse string to DecoratedInterval" begin

0 commit comments

Comments
 (0)