Skip to content

Commit

Permalink
earlier error when no initial interval is found (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Dec 21, 2022
1 parent d2182bc commit af6a491
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/find_zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ julia> find_zeros(f, 0, 10, no_pts=21) # too hard for default
```
!!! note
There are two cases where the number of zeros may be underreported:
Some cases where the number of zeros may be underreported:
* if the initial interval, `(a,b)`, is too wide
* if there are zeros that are very nearby
* the function is flat, e.g., `x->0`.
----
Expand Down Expand Up @@ -325,6 +326,7 @@ function find_zeros(f, a, b=nothing; no_pts=12, k=8, naive=false, kwargs...)
a0 = find_non_zero(f, a0, b0, xatol, xrtol, atol, rtol)
b0 = find_non_zero(f, b0, a0, xatol, xrtol, atol, rtol)

(isnan(a0) || isnan(b0)) && throw(DomainError("no non-zero initial points found."))
_fz!(zs, f, a0, b0, no_pts, k) # initial zeros

ints = Interval{T}[] # collect subintervals
Expand Down
3 changes: 3 additions & 0 deletions test/test_find_zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ end

# test with constant function
@test isempty(find_zeros(x -> 4, -10, 10))

# test with zero function (Issue #339)
@test_throws DomainError find_zeros(x -> 0, -2, 2)
end

@testset "find_zeros: not Float64 types" begin
Expand Down

0 comments on commit af6a491

Please sign in to comment.