Zhe*_*lov 5 java integer-overflow guava long-integer
public static long checkedAdd(long a, long b) {
long result = a + b;
checkNoOverflow((a ^ b) < 0 | (a ^ result) >= 0);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我感兴趣为什么布尔逻辑| 在这里使用.为什么不使用条件短路||?
该课程的第一条评论:
// NOTE: Whenever both tests are cheap and functional, it's faster to use
// &, | instead of &&, ||
Run Code Online (Sandbox Code Playgroud)
更多上下文:/sf/answers/798848501/
| 归档时间: |
|
| 查看次数: |
142 次 |
| 最近记录: |