Skip to content

Commit 801b6c5

Browse files
tkoolendpsanders
authored andcommitted
Add typemin, typemax, ::Type version of eps. (#108)
* Add typemin, typemax, type version of eps. * Make eps (and dist) return an Interval. * Address #108 (comment).
1 parent f063701 commit 801b6c5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/IntervalArithmetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using AdjacentFloats
1212
import Base:
1313
+, -, *, /, //, fma,
1414
<, >, ==, !=, , ^, <=,
15-
in, zero, one, abs, abs2, real, min, max,
15+
in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
1616
sqrt, exp, log, sin, cos, tan, inv,
1717
exp2, exp10, log2, log10,
1818
asin, acos, atan, atan2,

src/intervals/arithmetic.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ end
5050
const = strictprecedes # \prec
5151

5252

53-
# zero, one
53+
# zero, one, typemin, typemax
5454
zero(a::Interval{T}) where T<:Real = Interval(zero(T))
5555
zero(::Type{Interval{T}}) where T<:Real = Interval(zero(T))
5656
one(a::Interval{T}) where T<:Real = Interval(one(T))
5757
one(::Type{Interval{T}}) where T<:Real = Interval(one(T))
58-
58+
typemin(::Type{Interval{T}}) where T<:AbstractFloat = wideinterval(typemin(T))
59+
typemax(::Type{Interval{T}}) where T<:AbstractFloat = wideinterval(typemax(T))
60+
typemin(::Type{Interval{T}}) where T<:Integer = Interval(typemin(T))
61+
typemax(::Type{Interval{T}}) where T<:Integer = Interval(typemax(T))
5962

6063
## Addition and subtraction
6164

@@ -252,8 +255,8 @@ end
252255

253256

254257
dist(a::Interval, b::Interval) = max(abs(a.lo-b.lo), abs(a.hi-b.hi))
255-
eps(a::Interval) = max(eps(a.lo), eps(a.hi))
256-
258+
eps(a::Interval) = Interval(max(eps(a.lo), eps(a.hi)))
259+
eps(::Type{Interval{T}}) where T<:Real = Interval(eps(T))
257260

258261
## floor, ceil, trunc, sign, roundTiesToEven, roundTiesToAway
259262
function floor(a::Interval)

test/interval_tests/consistency.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ c = @interval(0.25, 4.0)
2525
@test one(a) == big(1.0)
2626
@test !(a == b)
2727
@test a != b
28+
@test eps(typeof(a)) === eps(one(typeof(a)))
29+
@test typemin(typeof(a)) === Interval(-Inf, nextfloat(-Inf))
30+
@test typemax(typeof(a)) === Interval(prevfloat(Inf), Inf)
31+
@test typemin(a) === typemin(typeof(a))
32+
@test typemax(a) === typemax(typeof(a))
33+
@test typemin(Interval{Int64}) === Interval(typemin(Int64))
34+
@test typemax(Interval{Int64}) === Interval(typemax(Int64))
2835

2936
@test a == Interval(a.lo, a.hi)
3037
@test @interval(1, Inf) == Interval(1.0, Inf)

0 commit comments

Comments
 (0)