1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
JustAHuman-xD 2023-03-02 06:20:00 -06:00
parent 1d24e832b5
commit cc557a19cf

View File

@ -286,7 +286,7 @@ public final class NumberUtils {
* This detects if 2 integers will overflow/underflow and if they will, returns the corresponding value
* @param a the first integer
* @param b the second integer
* @return {@link Integer#MAX_VALUE} if overflow detected, {@link Integer#MIN_VALUE} if underflow detected, otherwise the sum of i1 and i2
* @return {@link Integer#MAX_VALUE} if overflow detected, {@link Integer#MIN_VALUE} if underflow detected, otherwise the sum of a and b
*/
public static int flowSafeAddition(int a, int b) {
return limitedAddition(a, b, Integer.MAX_VALUE, Integer.MIN_VALUE);
@ -298,7 +298,7 @@ public final class NumberUtils {
* @param b the second integer
* @param max the maximum value for the operation
* @param min the minimum value for the operation
* @return {@link Integer#MAX_VALUE} if overflow detected, {@link Integer#MIN_VALUE} if underflow detected, otherwise the sum of i1 and i2
* @return max if overflow detected, min if underflow detected, otherwise the sum of a and b
*/
public static int limitedAddition(int a, int b, int max, int min) {
boolean willOverflow = (a == max && b > 0 || b == max && a > 0) || a > 0 && b > max - a;