Skip to content

Commit 36deaed

Browse files
committed
Fix a bug in abs_diff
These implementations of `abs_diff` were added in c2ff1b3 ("Completely overhaul fuzz testing"), but the signed implementation is wrong when |x| + |y| exceeds the integer's limits (e.g. `(-128).abs_diff(1)` should be 128 but currently these return 127. Resolve this by just using `std`'s implementation since that is stable now. This isn't used anywhere critical, we probably just weren't hitting the edge case.
1 parent a09218f commit 36deaed

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/int/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,7 @@ macro_rules! int_impl {
240240
}
241241

242242
fn abs_diff(self, other: Self) -> Self {
243-
if self < other {
244-
other.wrapping_sub(self)
245-
} else {
246-
self.wrapping_sub(other)
247-
}
243+
self.abs_diff(other)
248244
}
249245

250246
int_impl_common!($uty);
@@ -277,7 +273,7 @@ macro_rules! int_impl {
277273
}
278274

279275
fn abs_diff(self, other: Self) -> $uty {
280-
self.wrapping_sub(other).wrapping_abs() as $uty
276+
self.abs_diff(other)
281277
}
282278

283279
int_impl_common!($ity);

0 commit comments

Comments
 (0)