Skip to content

Commit

Permalink
BUG: special: fix square root conventions in clpmn and lpmn
Browse files Browse the repository at this point in the history
Having the branch cut in (-1, 1) requires some care in the square roots.
  • Loading branch information
pv committed Aug 27, 2013
1 parent de82d0d commit 815393d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scipy/special/specfun/specfun.f
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ SUBROUTINE CLPMN(MM,M,N,X,Y,CPM,CPD)
20 CONTINUE
RETURN
ENDIF
C sqrt(z^2 - 1) with branch cut between [-1, 1]
ZQ=CDSQRT(Z*Z-1.0D0)
IF (X.LT.0d0) THEN
ZQ=-ZQ
END IF
ZS=(Z*Z-1.0D0)
DO 25 I=1,M
C DLMF 14.7.15
Expand Down Expand Up @@ -6991,6 +6995,8 @@ SUBROUTINE LPMN(MM,M,N,X,PM,PD)
LS=1
IF (DABS(X).GT.1.0D0) LS=-1
XQ=DSQRT(LS*(1.0D0-X*X))
C Ensure connection to the complex-valued function for |x| > 1
IF (X.LT.-1d0) XQ=-XQ
XS=LS*(1.0D0-X*X)
DO 30 I=1,M
30 PM(I,I)=-LS*(2.0D0*I-1.0D0)*XQ*PM(I-1,I-1)
Expand Down

0 comments on commit 815393d

Please sign in to comment.