How to subtract two i64s and get a u64 result

I have two i64s, I know one is greater than the other, and I want to get their difference as a u64. I've tried (a - b) as u64, but this panics when a - b overflows as an i64. (I don't really care what happens if b is greater than a, but a panic would be nice.)

abs_diff?

2 Likes

Thank you!

a.wrapping_sub(b) as u64.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.