Compute the minimum or maximum of two integers without branching | Python3 implementation of the approach ; Function to find minimum of x and y ; Function to find maximum of x and y ; Driver code
import sys ; NEW_LINE CHAR_BIT = 8 ; NEW_LINE INT_BIT = sys . getsizeof ( int ( ) ) ; NEW_LINE def Min ( x , y ) : NEW_LINE INDENT return y + ( ( x - y ) & ( ( x - y ) >> ( INT_BIT * CHAR_BIT - 1 ) ) ) ; NEW_LINE DEDENT def Max ( x , y ) : NEW_LINE INDENT return x - ( ( x - y ) & ( ( x - y ) >> ( INT_BIT * CHAR_BIT - 1 ) ) ) ; NEW_LINE DEDENT x = 15 ; NEW_LINE y = 6 ; NEW_LINE print ( " Minimum ▁ of " , x , " and " , y , " is " , Min ( x , y ) ) ; NEW_LINE print ( " Maximum ▁ of " , x , " and " , y , " is " , Max ( x , y ) ) ; NEW_LINE