Skip to content

Commit

Permalink
Use -0.0 as the neutral additive float
Browse files Browse the repository at this point in the history
-0.0 +  0.0 is  0.0
-0.0 + -0.0 is -0.0

Thus, the float additive-zero is actually -0.0, not its positive cousin.
This change aligns with a recent change to the impl of Sum for floats,
in rust-lang/rust@4908188
  • Loading branch information
workingjubilee committed Sep 12, 2024
1 parent 5fb43ca commit 72031b0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/core_simd/src/simd/num/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ macro_rules! impl_trait {
self.as_array().iter().sum()
} else {
// Safety: `self` is a float vector
unsafe { core::intrinsics::simd::simd_reduce_add_ordered(self, 0.) }
unsafe { core::intrinsics::simd::simd_reduce_add_ordered(self, -0.) }
}
}

Expand Down

0 comments on commit 72031b0

Please sign in to comment.