Skip to content

Commit cd90acb

Browse files
committed
fix an inexact error
1 parent 1ed1f7e commit cd90acb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/classical/jacobi.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,25 @@ function _jacobi_convert_b(a, b, k, T) # Jacobi(a, b+k) \ Jacobi(a, b)
312312
end
313313
end
314314

315+
"""
316+
_approx_integer(x; kw...)
317+
318+
Returns `y::Integer` such that `isapprox(x,y; kw...)` is `true`. Throws `InexactError` if `y` does not exist.
319+
"""
320+
function _approx_integer(x; kw...)
321+
y = round(x)
322+
if !isapprox(x,y; kw...)
323+
throw(InexactError(_approx_integer, x))
324+
end
325+
Integer(y)
326+
end
327+
315328
function \(A::Jacobi, B::Jacobi)
316329
T = promote_type(eltype(A), eltype(B))
317330
aa, ab = A.a, A.b
318331
ba, bb = B.a, B.b
319-
ka = Integer(aa-ba)
320-
kb = Integer(ab-bb)
332+
ka = _approx_integer(aa-ba)
333+
kb = _approx_integer(ab-bb)
321334
if ka >= 0
322335
C1 = _jacobi_convert_a(ba, ab, ka, T)
323336
if kb >= 0

test/test_jacobi.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ import ClassicalOrthogonalPolynomials: recurrencecoefficients, basis, MulQuasiMa
147147
# special weighted conversions
148148
W = (JacobiWeight(-1,-1) .* Jacobi(0,0)) \ Jacobi(0,0)
149149
@test ((JacobiWeight(-1,-1) .* Jacobi(0,0)) * W)[0.1,1:10] Jacobi(0,0)[0.1,1:10]
150+
151+
# potential inexact errors
152+
Jacobi(1.9,1.9) \ Jacobi(0.9,0.9) # isinteger(1.9-0.9) = false
150153
end
151154

152155
@testset "Derivative" begin

0 commit comments

Comments
 (0)