Skip to content

Conversation

@jackylee-ch
Copy link
Contributor

Why are the changes needed?

As discussed in #46811 , we use Math.abs to get positive numbers, as it offers better readability..

Does this PR introduce any user-facing change?

No.

How was this patch tested?

GA

Was this patch authored or co-authored using generative AI tooling?

No.

@jackylee-ch jackylee-ch force-pushed the use_abs_to_get_positive_numbers branch from cb0dac8 to 3054181 Compare June 1, 2024 04:24
@jackylee-ch jackylee-ch force-pushed the use_abs_to_get_positive_numbers branch from 3054181 to faeb89a Compare June 1, 2024 14:48
@LuciferYang
Copy link
Contributor

If overflow, realTaskId.toInt & Int.MaxValue and math.abs are not equal

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

@github-actions
Copy link

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

@github-actions github-actions bot added the Stale label Sep 12, 2024
@LuciferYang
Copy link
Contributor

I can't remember clearly, do we still need to complete this PR?

@LuciferYang LuciferYang removed the Stale label Sep 12, 2024
@github-actions
Copy link

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

@github-actions github-actions bot added the Stale label Dec 22, 2024
@github-actions github-actions bot closed this Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants