#NEWLINE# @ lower_builtin ( round , types . Float , types . Integer ) #NEWLINE# def round_impl_binary( context , builder , sig , args ) : #NEWLINE# #INDENT# fltty = sig . args [ 0 ] #NEWLINE# _round = types . ExternalFunction ( _round_intrinsic ( fltty ) , typing . signature ( fltty , fltty ) ) #NEWLINE# def round_ndigits( x , ndigits ) : #NEWLINE# #INDENT# if ( math . isinf ( x ) or math . isnan ( x ) ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# if ( ndigits >= 0 ) : #NEWLINE# #INDENT# if ( ndigits > 22 ) : #NEWLINE# #INDENT# pow1 = ( 10.0 ** ( ndigits - 22 ) ) #NEWLINE# pow2 = 1e+22 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pow1 = ( 10.0 ** ndigits ) #NEWLINE# pow2 = 1.0 #NEWLINE# #UNINDENT# y = ( ( x * pow1 ) * pow2 ) #NEWLINE# if math . isinf ( y ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# return ( ( _round ( y ) / pow2 ) / pow1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pow1 = ( 10.0 ** ( - ndigits ) ) #NEWLINE# y = ( x / pow1 ) #NEWLINE# return ( _round ( y ) * pow1 ) #NEWLINE# #UNINDENT# #UNINDENT# res = context . compile_internal ( builder , round_ndigits , sig , args ) #NEWLINE# return impl_ret_untracked ( context , builder , sig . return_type , res )