-
-
Save vietj/14c8ba5cedeb022248d9112d98748c3f 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