Skip to content

Commit

Permalink
Adds zero(::Type{Interval}) and one(::Type{Interval}), and tests
Browse files Browse the repository at this point in the history
The reason to add these methods is to keep up with the usage of zero/one
in Base, and because it is useful to play smoothly with TaylorSeries.
It also deletes two methods of ⊆, which are already in the package,
which were left in root_finding_tests.jl
  • Loading branch information
Luis Benet committed Sep 1, 2015
1 parent 2e2f492 commit 2fcee54
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ in(x::Real, a::Interval) = a.lo <= x <= a.hi
## zero and one functions

zero{T}(a::Interval{T}) = Interval(zero(T))
zero{T}(::Type{Interval{T}}) = Interval(zero(T))
one{T}(a::Interval{T}) = Interval(one(T))
zero{T}(::Type{Interval{T}}) = Interval(zero(T))

This comment has been minimized.

Copy link
@dpsanders

dpsanders Sep 1, 2015

Member

I think you mean one here...

This comment has been minimized.

Copy link
@lbenet

lbenet Sep 1, 2015

Member

Ups... sorry. I'll send you right a way a correction

This comment has been minimized.

Copy link
@lbenet

lbenet Sep 1, 2015

Member

Done.



## Addition and subtraction
Expand Down
2 changes: 2 additions & 0 deletions test/interval_tests/consistency_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ facts("Consistency tests") do
@fact isa( zero(b), Interval ) --> true

@fact zero(b) --> 0.0
@fact zero(b) == zero(typeof(b)) --> true
@fact one(a) --> 1.0
@fact one(a) == one(typeof(a)) --> true

This comment has been minimized.

Copy link
@dpsanders

dpsanders Sep 1, 2015

Member

So it's surprising is this works. Or is there a generic method?

This comment has been minimized.

Copy link
@lbenet

lbenet Sep 1, 2015

Member

I'm not quite sure I understand what you mean,
It is not surprising that it works; I simply added another method, so zero/one work with the DataType, which is used in the constructor for Taylor1

This comment has been minimized.

Copy link
@dpsanders

dpsanders Sep 1, 2015

Member

I meant that one(T) for a type T is defined generically -- see my other comment.

@fact one(a) --> big(1.0)
@fact a == b --> false
@fact a != b --> true
Expand Down
2 changes: 0 additions & 2 deletions test/root_finding_tests/root_finding_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ big_pi = @interval(pi)
set_interval_precision(Float64)
float_pi = @interval(pi)

Base.⊆(a::Interval, b::Root) = a b.interval # the Root object has the interval in the first entry
Base.⊆(a::Root, b::Root) = a.interval b.interval

# Using precision "only" 256 leads to overestimation of the true roots for `cos`
# i.e the Newton method gives more accurate results!
Expand Down

0 comments on commit 2fcee54

Please sign in to comment.