Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change neutral element of <fNN as iter::Sum> to neg_zero #129321

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/core/src/iter/traits/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ macro_rules! float_sum_product {
impl Sum for $a {
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
iter.fold(
0.0,
-0.0,
#[rustc_inherit_overflow_checks]
|a, b| a + b,
)
Expand All @@ -126,7 +126,7 @@ macro_rules! float_sum_product {
impl<'a> Sum<&'a $a> for $a {
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
iter.fold(
0.0,
-0.0,
#[rustc_inherit_overflow_checks]
|a, b| a + b,
)
Expand Down
27 changes: 27 additions & 0 deletions library/core/tests/num/float_iter_sum_identity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#[test]
fn f32_ref() {
let x: f32 = -0.0;
let still_x: f32 = [x].iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f32_own() {
let x: f32 = -0.0;
let still_x: f32 = [x].into_iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f64_ref() {
let x: f64 = -0.0;
let still_x: f64 = [x].iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f64_own() {
let x: f64 = -0.0;
let still_x: f64 = [x].into_iter().sum();
assert_eq!(1. / x, 1. / still_x)
}
1 change: 1 addition & 0 deletions library/core/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod int_log;
mod ops;
mod wrapping;

mod float_iter_sum_identity;
mod ieee754;
mod nan;

Expand Down
Loading