From 0ce47b3c1f200f59e5459eb50fb6c2715c3b2259 Mon Sep 17 00:00:00 2001 From: Aaron Kutch Date: Thu, 10 Dec 2020 17:00:45 -0600 Subject: [PATCH] fix abs_diff bug --- library/compiler-builtins/src/int/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/compiler-builtins/src/int/mod.rs b/library/compiler-builtins/src/int/mod.rs index e50b2e608383..a186a95aa666 100644 --- a/library/compiler-builtins/src/int/mod.rs +++ b/library/compiler-builtins/src/int/mod.rs @@ -250,7 +250,11 @@ macro_rules! int_impl { } fn abs_diff(self, other: Self) -> Self { - (self.wrapping_sub(other) as $ity).wrapping_abs() as $uty + if self < other { + other.wrapping_sub(self) + } else { + self.wrapping_sub(other) + } } int_impl_common!($uty);