Skip to content

Commit e9782ce

Browse files
committed
Fix a bug in abs_diff
These were taken from `compiler-builtins` but the implementation has a bug near the integer limits. Fixed in `compiler-builtins` by using `core`'s implementation at [1], this is the corresponding fix for `libm`. [1]: rust-lang#736
1 parent 81f2dc6 commit e9782ce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/math/support/int_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ macro_rules! int_impl {
184184
}
185185

186186
fn abs_diff(self, other: Self) -> Self {
187-
if self < other { other.wrapping_sub(self) } else { self.wrapping_sub(other) }
187+
self.abs_diff(other)
188188
}
189189

190190
int_impl_common!($uty);
@@ -221,7 +221,7 @@ macro_rules! int_impl {
221221
}
222222

223223
fn abs_diff(self, other: Self) -> $uty {
224-
self.wrapping_sub(other).wrapping_abs() as $uty
224+
self.abs_diff(other)
225225
}
226226

227227
int_impl_common!($ity);

0 commit comments

Comments
 (0)