Returns 1 if x < y as unsigned integers, and 0 otherwise. Assumes that x - y fits into a signed int. The implementation is branch-free, and benchmarks suggest it is measurably (if narrowly) faster than the straightforward ternary expression.
(int x, int y)
| 107 | */ |
| 108 | |
| 109 | @VisibleForTesting |
| 110 | static int lessThanBranchFree(int x, int y) { |
| 111 | // The double negation is optimized away by normal Java, but is necessary for GWT |
| 112 | // to make sure bit twiddling works as expected. |
| 113 | return ~~ (x - y) >>> (Integer.SIZE - 1); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode. |
no outgoing calls
no test coverage detected