Java Branchless Programming

1k Views Asked by At

I recently heard about branchless programming and found some simple examples like:

int getSmaller( int a, int b )
{
    if ( a < b )
        return a;
    else
        return b;
}

Which can be written as

int getSmaller( int a, int b )
{
    return a * ( a < b ) + b * ( b <= a );
}

This all works because a < b returns true/false or in cpp 1/0. I am mainly programming in Java in as far as I know true/false is not equal to 1/0 so how would you write a similar solution in Java

0

There are 0 best solutions below