diff --git a/mpmath/functions/bessel.py b/mpmath/functions/bessel.py index 836bed61..7c69afaa 100644 --- a/mpmath/functions/bessel.py +++ b/mpmath/functions/bessel.py @@ -180,11 +180,17 @@ def besselk(ctx, n, z, derivative=0, **kwargs): @defun_wrapped def hankel1(ctx,n,x,**kwargs): - return ctx.besselj(n,x,**kwargs) + ctx.j*ctx.bessely(n,x,**kwargs) + def terms(): + return [ctx.besselj(n,x,**kwargs), + ctx.j*ctx.bessely(n,x,**kwargs)] + return ctx.sum_accurately(terms) @defun_wrapped def hankel2(ctx,n,x,**kwargs): - return ctx.besselj(n,x,**kwargs) - ctx.j*ctx.bessely(n,x,**kwargs) + def terms(): + return [ctx.besselj(n,x,**kwargs), + -ctx.j*ctx.bessely(n,x,**kwargs)] + return ctx.sum_accurately(terms) @defun_wrapped def whitm(ctx,k,m,z,**kwargs): diff --git a/mpmath/tests/test_functions2.py b/mpmath/tests/test_functions2.py index 188327fc..610f7ca9 100644 --- a/mpmath/tests/test_functions2.py +++ b/mpmath/tests/test_functions2.py @@ -2433,3 +2433,7 @@ def test_issue_634(): def test_issue_908(): assert mp.besselj(-10+0j, 0+0j) == 0 + +def test_issue_637(): + assert hankel1(1, 1 + 30j).ae(-7.25495e-15 - 1.17346e-14j) + assert hankel2(1, 1 - 30j).ae(-7.25495e-15 + 1.17346e-14j)