You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/27 10:51:51 UTC

[GitHub] [flink] wangyang0918 commented on a change in pull request #12357: [FLINK-17958][core] Fix MathUtils#divideRoundUp bug for handling zero or negative values.

wangyang0918 commented on a change in pull request #12357:
URL: https://github.com/apache/flink/pull/12357#discussion_r431025047



##########
File path: flink-core/src/main/java/org/apache/flink/util/MathUtils.java
##########
@@ -209,12 +209,18 @@ public static long flipSignBit(long in) {
 
 	/**
 	 * Divide and rounding up to integer.
-	 * E.g., divideRoundUp(3, 2) returns 2.
+	 * E.g., divideRoundUp(3, 2) returns 2, divideRoundUp(0, 3) returns 0.
+	 * Note that this method does not support negative values.
 	 * @param dividend value to be divided by the divisor
 	 * @param divisor value by which the dividend is to be divided
 	 * @return the quotient rounding up to integer
 	 */
 	public static int divideRoundUp(int dividend, int divisor) {
+		Preconditions.checkArgument(dividend >= 0, "Negative dividend is not supported.");
+		Preconditions.checkArgument(divisor > 0, "Negative or zero divisor is not supported.");
+		if (dividend == 0) {

Review comment:
       nit: Could be done in one line.
   `return dividend == 0 ? 0 : (dividend - 1) / divisor + 1`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org