Skip to content

Commit

Permalink
Fix a bug in abs_diff
Browse files Browse the repository at this point in the history
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/compiler-builtins#736
  • Loading branch information
tgross35 committed Dec 22, 2024
1 parent 81f2dc6 commit e9782ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/math/support/int_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ macro_rules! int_impl {
}

fn abs_diff(self, other: Self) -> Self {
if self < other { other.wrapping_sub(self) } else { self.wrapping_sub(other) }
self.abs_diff(other)
}

int_impl_common!($uty);
Expand Down Expand Up @@ -221,7 +221,7 @@ macro_rules! int_impl {
}

fn abs_diff(self, other: Self) -> $uty {
self.wrapping_sub(other).wrapping_abs() as $uty
self.abs_diff(other)
}

int_impl_common!($ity);
Expand Down

0 comments on commit e9782ce

Please sign in to comment.