R
Roedy Green
Hmm, 9th candidate is here:
return (int)( diff >>> 32 ) | ( (int)diff | (int)diff << 1 ) >>> 1;
wibble2 in now ascribed to piotr under the name kobzda.
public static final int kobzda ( long diff )
{
// the beauty of this method is most of the work is in int,
not long
// which works well on 32-bit machines.
return (int) ( diff >>> 32 ) | (int)diff >>> 1 | (int)diff &
1;
}
Poiter has onother algorithm he called signHalf
public static final int signHalf ( long diff )
{
return ( diff <= 0 ) ? (int) ( diff >>> 32 ) : 1;
}