#NEWLINE# def mpc_besseljn( n , z , prec , rounding = round_fast ) : #NEWLINE# #INDENT# negate = ( ( n < 0 ) and ( n & 1 ) ) #NEWLINE# n = abs ( n ) #NEWLINE# origprec = prec #NEWLINE# ( zre , zim ) = z #NEWLINE# mag = max ( ( zre [ 2 ] + zre [ 3 ] ) , ( zim [ 2 ] + zim [ 3 ] ) ) #NEWLINE# prec += ( ( 20 + ( n * bitcount ( n ) ) ) + abs ( mag ) ) #NEWLINE# if ( mag < 0 ) : #NEWLINE# #INDENT# prec -= ( n * mag ) #NEWLINE# #UNINDENT# zre = to_fixed ( zre , prec ) #NEWLINE# zim = to_fixed ( zim , prec ) #NEWLINE# z2re = ( ( ( zre ** 2 ) - ( zim ** 2 ) ) >> prec ) #NEWLINE# z2im = ( ( zre * zim ) >> ( prec - 1 ) ) #NEWLINE# if ( not n ) : #NEWLINE# #INDENT# sre = tre = ( MPZ_ONE << prec ) #NEWLINE# sim = tim = MPZ_ZERO #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( re , im ) = complex_int_pow ( zre , zim , n ) #NEWLINE# sre = tre = ( ( re // ifac ( n ) ) >> ( ( ( n - 1 ) * prec ) + n ) ) #NEWLINE# sim = tim = ( ( im // ifac ( n ) ) >> ( ( ( n - 1 ) * prec ) + n ) ) #NEWLINE# #UNINDENT# k = 1 #NEWLINE# while ( ( abs ( tre ) + abs ( tim ) ) > 3 ) : #NEWLINE# #INDENT# p = ( ( ( - 4 ) * k ) * ( k + n ) ) #NEWLINE# ( tre , tim ) = ( ( ( tre * z2re ) - ( tim * z2im ) ) , ( ( tim * z2re ) + ( tre * z2im ) ) ) #NEWLINE# tre = ( ( tre // p ) >> prec ) #NEWLINE# tim = ( ( tim // p ) >> prec ) #NEWLINE# sre += tre #NEWLINE# sim += tim #NEWLINE# k += 1 #NEWLINE# #UNINDENT# if negate : #NEWLINE# #INDENT# sre = ( - sre ) #NEWLINE# sim = ( - sim ) #NEWLINE# #UNINDENT# re = from_man_exp ( sre , ( - prec ) , origprec , rounding ) #NEWLINE# im = from_man_exp ( sim , ( - prec ) , origprec , rounding ) #NEWLINE# return ( re , im )