srowen commented on a change in pull request #23420: [SPARK-26508][Core][SQL] 
Address warning messages in Java reported at lgtm.com
URL: https://github.com/apache/spark/pull/23420#discussion_r244590283
 
 

 ##########
 File path: 
common/network-common/src/main/java/org/apache/spark/network/util/ByteUnit.java
 ##########
 @@ -54,7 +54,7 @@ public double toBytes(long d) {
     if (d < 0) {
       throw new IllegalArgumentException("Negative size value. Size must be 
positive: " + d);
     }
-    return d * multiplier;
+    return d * (double)multiplier;
 
 Review comment:
   We need a space after casts. I suppose the point is to avoid overflow when 
the result is going to be a double anyway, at the cost of precision maybe. I 
tested, and the precision issue won't matter, but then again, there's no reason 
this method should return `double`. There is no such thing as 0.5 bytes.
   
   I think we can just fix that for Spark 3; its value is used as a `long` or 
`int` everywhere anyway.
   
   While here, I think I'd also fix the expressions like `(long) 
Math.pow(1024L, 2L)` above. The multipliers should be `1L << 10`, `1L << 20`, 
... `1L << 50`. There's again no point there in using floating point math.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to