Skip to content

Commit

Permalink
Improve code by using wrapping_neg
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 21, 2024
1 parent d318878 commit 81d470f
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,13 @@ macro_rules! impl_Display {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for $signed {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let is_nonnegative = *self >= 0;

if !is_nonnegative {
if *self < 0 {
#[cfg(not(feature = "optimize_for_size"))]
{
// convert the negative num to positive by summing 1 to its 2s complement
return (!self as $unsigned).wrapping_add(1)._fmt(false, f);
}
#[cfg(feature = "optimize_for_size")]
{
// convert the negative num to positive by summing 1 to its 2s complement
return $gen_name((!self.$conv_fn()).wrapping_add(1), false, f);
}
}
Expand Down

0 comments on commit 81d470f

Please sign in to comment.