#NEWLINE# def _calcDouble( x ) : #NEWLINE# #INDENT# assert ( x == normalizeDouble ( x ) ) #NEWLINE# if ( x in lookup . DOUBLES ) : #NEWLINE# #INDENT# return lookup . DOUBLES [ x ] #NEWLINE# #UNINDENT# exponent = ( ( ( x >> 52 ) & 2047 ) - 1023 ) #NEWLINE# mantissa = ( x % ( 1 << 52 ) ) #NEWLINE# if ( exponent == ( - 1023 ) ) : #NEWLINE# #INDENT# exponent += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mantissa += ( 1 << 52 ) #NEWLINE# #UNINDENT# exponent -= 52 #NEWLINE# if ( x & DOUBLE_SIGN ) : #NEWLINE# #INDENT# mantissa = ( - mantissa ) #NEWLINE# #UNINDENT# abs_exponent = abs ( exponent ) #NEWLINE# exponent_parts = bytearray ( ) #NEWLINE# part63 = ( abs_exponent // 63 ) #NEWLINE# if part63 : #NEWLINE# #INDENT# if ( exponent < 0 ) : #NEWLINE# #INDENT# exponent_parts . extend ( [ DCONST_1 , LCONST_1 , ICONST_M1 , LSHL , L2D , DDIV ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# exponent_parts . extend ( [ LCONST_1 , ICONST_M1 , LSHL , L2D ] ) #NEWLINE# #UNINDENT# if ( part63 & 1 ) : #NEWLINE# #INDENT# mantissa = ( - mantissa ) #NEWLINE# #UNINDENT# last_needed = ( part63 & 1 ) #NEWLINE# stack = [ 1 ] #NEWLINE# for bi in range ( 1 , part63 . bit_length ( ) ) : #NEWLINE# #INDENT# exponent_parts . append ( DUP2 ) #NEWLINE# stack . append ( stack [ ( - 1 ) ] ) #NEWLINE# if last_needed : #NEWLINE# #INDENT# exponent_parts . append ( DUP2 ) #NEWLINE# stack . append ( stack [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# exponent_parts . append ( DMUL ) #NEWLINE# stack . append ( ( stack . pop ( ) + stack . pop ( ) ) ) #NEWLINE# last_needed = ( part63 & ( 1 << bi ) ) #NEWLINE# #UNINDENT# assert ( ( sum ( stack ) == part63 ) and ( len ( stack ) == bin ( part63 ) . count ( '1' ) ) ) #NEWLINE# exponent_parts . extend ( ( [ DMUL ] * bin ( part63 ) . count ( '1' ) ) ) #NEWLINE# #UNINDENT# rest = ( abs_exponent % 63 ) #NEWLINE# if rest : #NEWLINE# #INDENT# exponent_parts . append ( LCONST_1 ) #NEWLINE# exponent_parts . extend ( _calcInt ( rest ) ) #NEWLINE# exponent_parts . extend ( [ LSHL , L2D ] ) #NEWLINE# exponent_parts . append ( ( DDIV if ( exponent < 0 ) else DMUL ) ) #NEWLINE# #UNINDENT# return ( ( _calcLong ( mantissa ) + bytes ( [ L2D ] ) ) + exponent_parts )