Skip to content

Commit 839bb20

Browse files
dpsanderslbenet
authored andcommitted
Fix a - x and add tests (#131)
* Fix a - x for constant a * Add a few tests of op(a, x) for constants a * Typo
1 parent afb03a3 commit 839bb20

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/intervals/arithmetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function -(a::Interval{T}, b::T) where {T<:Real}
7777
end
7878
function -(b::T, a::Interval{T}) where {T<:Real}
7979
isempty(a) && return emptyinterval(T)
80-
@round(b - a.lo, b - a.hi)
80+
@round(b - a.hi, b - a.lo)
8181
end
8282

8383
function +(a::Interval{T}, b::Interval{T}) where T<:Real

test/interval_tests/numeric.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ setprecision(Interval, Float64)
3939
@test diam(a) == eps(1.e-20)
4040
end
4141

42+
@testset "Arithmetic with constants" begin
43+
x = 1..2
44+
45+
@test 0.1 + x == Interval(1.0999999999999999, 2.1)
46+
@test 3.0 - x == 1..2
47+
@test 3.1 - x == Interval(1.1, 2.1)
48+
@test 0.1 * (1..1) == Interval(0.1, 0.1)
49+
@test (1..1) / 10.0 == Interval(0.09999999999999999, 0.1)
50+
51+
end
52+
4253
@testset "Power tests" begin
4354
@test @interval(0,3) ^ 2 == Interval(0, 9)
4455
@test @interval(2,3) ^ 2 == Interval(4, 9)

0 commit comments

Comments
 (0)