Somehow I do not see comments I made earlier, so I'll dare asking again: 

1. why do you need to special-case phi=0, pi (fabs(x)==1) here? 
2. `mp > n` seems to be already covered in line 17 above (shortcut, return nan), so that prefactor = 0 branch is unreachable.