Repository: JuliaMath/Roots.jl (julia)

Issue:
Error with Float32
This was unexpected:

```
julia> using Roots

julia> solve(ZeroProblem(x -> x^2 - 2.0f0, 2.0))
1.4142135623730951

julia> solve(ZeroProblem(x -> x^2 - 2.0f0, 2.0f0))
ERROR: MethodError: no method matching Roots.UnivariateZeroState(::Float64, ::Float32, ::Float32, ::Float32)

Closest candidates are:
  Roots.UnivariateZeroState(::T, ::T, ::S, ::S) where {T, S}
   @ Roots ~/.julia/packages/Roots/BMiNe/src/state.jl:3

Stacktrace:
 [1] setproperties_object(obj::Roots.UnivariateZeroState{Float32, Float32}, patch::@NamedTuple{xn1::Float64})
   @ ConstructionBase ~/.julia/packages/ConstructionBase/JFKjZ/src/ConstructionBase.jl:217
 [2] setproperties(obj::Roots.UnivariateZeroState{Float32, Float32}, patch::@NamedTuple{xn1::Float64})
   @ ConstructionBase ~/.julia/packages/ConstructionBase/JFKjZ/src/ConstructionBase.jl:131
 [3] set
   @ ~/.julia/packages/Accessors/81CPQ/src/optics.jl:399 [inlined]
 [4] solve!(𝐙::Roots.ZeroProblemIterator{…}; verbose::Bool)
   @ Roots ~/.julia/packages/Roots/BMiNe/src/hybrid.jl:92
 [5] solve!
   @ ~/.julia/packages/Roots/BMiNe/src/hybrid.jl:30 [inlined]
 [6] solve(::ZeroProblem{var"#8#9", Float32}; verbose::Bool, kwargs::@Kwargs{})
   @ Roots ~/.julia/packages/Roots/BMiNe/src/find_zero.jl:480
 [7] solve(::ZeroProblem{var"#8#9", Float32})
   @ Roots ~/.julia/packages/Roots/BMiNe/src/find_zero.jl:478
 [8] top-level scope
   @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 2700X Eight-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver1)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
```

Pull request description:
Close #421

Patch:
diff --git a/Project.toml b/Project.toml
index 652ada9f..21aeb577 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,6 +1,6 @@
 name = "Roots"
 uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
-version = "2.1.2"
+version = "2.1.3"
 
 [deps]
 ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
diff --git a/src/hybrid.jl b/src/hybrid.jl
index b3043390..712bf5db 100644
--- a/src/hybrid.jl
+++ b/src/hybrid.jl
@@ -80,7 +80,7 @@ function solve!(
         r, a, b = state0.xn1, state.xn0, state.xn1
         Δr = abs(r - b)
         Δx = abs(b - a)
-        ts, TB = 1e-3, 1e2 # too small, too big
+        ts, TB = one(r)/1000, 100*one(r) # too small, too big
         if Δr >= TB * Δx
             adj = true
             r = b + sign(r - b) * TB * Δx  ## too big


Test patch:
diff --git a/test/test_find_zero.jl b/test/test_find_zero.jl
index 6f53885f..ef4e136d 100644
--- a/test/test_find_zero.jl
+++ b/test/test_find_zero.jl
@@ -36,6 +36,7 @@ struct Order3_Test <: Roots.AbstractSecantMethod end
         @test find_zero(sin, 3.0, m) ≈ pi
         @test find_zero(sin, big(3), m) ≈ pi
         @test find_zero(sin, big(3.0), m) ≈ pi
+        @test find_zero(x -> x^2 - 2.0f0, 2.0f0, m) ≈ sqrt(2) # issue 421
     end
 
     ## defaults for method argument