LuciferYang commented on PR #46834:
URL: https://github.com/apache/spark/pull/46834#issuecomment-2144204312

   If overflow, `realTaskId.toInt & Int.MaxValue` and `math.abs` are not equal
   
   ```scala
   scala> val realTaskId = Long.MaxValue
   val realTaskId: Long = 9223372036854775807
   
   scala> val a = realTaskId.toInt
   val a: Int = -1
   
   scala> val b = realTaskId.toInt & Int.MaxValue
   val b: Int = 2147483647
   
   scala> val c= math.abs(realTaskId.toInt)
   val c: Int = 1
   ```
   
   ```scala
   scala> val realTaskId = Int.MaxValue.toLong + 1
   val realTaskId: Long = 2147483648
   
   scala> val a = realTaskId.toInt
   val a: Int = -2147483648
   
   scala> val b = realTaskId.toInt & Int.MaxValue
   val b: Int = 0
   
   scala> val c= math.abs(realTaskId.toInt)
   val c: Int = -2147483648
   ```
   Meanwhile, when an overflow occurs, `math.abs` may still return a negative 
value, so I suggest we continue using `& Int.MaxValue`


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to