Last active
October 23, 2018 14:07
-
-
Save franz1981/6ba4b8f031fcdc2b95cd33e149ea2f1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static long minusOneIfNotLongMax(long value) { | |
final long valueMinusOne = value - 1; | |
final long diffFromValue = value - Long.MAX_VALUE; | |
final long tmp = (diffFromValue - 1) >> 63; | |
final long mask = ((diffFromValue >> 63) ^ tmp) & tmp; | |
return (value & mask) | (valueMinusOne & (~mask)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment