-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Document Sum::sum
returns additive identities for []
#136710
Conversation
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
iterator.rs
@JakenHerman The reason is simple, as the negative zero is the true neutral element for floats: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9d21ada96adf24c4d3f9f2ef360c9630 fn main() {
assert!(( 0.0f32 + 0.0).is_sign_positive());
assert!((-0.0f32 + 0.0).is_sign_positive());
assert!(( 0.0f32 + -0.0).is_sign_positive());
assert!((-0.0f32 + -0.0).is_sign_negative());
} |
You would not expect the following to change the sign of the zero, would you?
|
iterator.rs
Sum::sum
returns additive identities
And I must note, the documentation was not technically incorrect. ...You can say it was uselessly correct, of course. |
Sum::sum
returns additive identitiesSum::sum
returns additive identities for []
I'm curious, can you describe the effects on the Tera applications? |
@workingjubilee Sure, I'll give a simple example... Consider an HTML/PDF report that sums up financial transactions then displays the total value of the summed transactions. If there are no transactions, the report would show that you spent That's a very simple example (and not the one I ran into), but it is the easiest I could come up with for illustrative purposes. I suppose the real solution on the template side would be to I committed your suggestion, as I think you summed up the expected return value better than I did. Thanks for your input. |
That is slightly unfortunate, yes. I guess that would have worked out fine if you just always had a positive value in the summation such that even if it reached zero, it would have been positive. @bors r+ rollup |
Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return. Co-authored-by: Jubilee <[email protected]>
1093779
to
4457f44
Compare
just a squash @bors r+ rollup |
…=workingjubilee Document `Sum::sum` returns additive identities for `[]` Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return. Relevant Commit: rust-lang@4908188 Relevant Pull Request: rust-lang#129321 --- The referenced commit causes unintended side effects on presentation layer applications like using Tera templates, for example. I'm not sure what the motivation was behind the original change, but it seems like more discussion should be put into this issue and potentially have that change reverted.
…kingjubilee Rollup of 13 pull requests Successful merges: - rust-lang#134999 (Add cygwin target.) - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`) - rust-lang#136397 (Add a comment pointing to ICE-136223) - rust-lang#136681 (resolve `llvm-config` path properly on cross builds) - rust-lang#136686 (Clean up `HashMap` and `HashSet` docs.) - rust-lang#136694 (Update minifier version to `0.3.4`) - rust-lang#136706 (compiler: mostly-finish `rustc_abi` updates) - rust-lang#136710 (Document `Sum::sum` returns additive identities for `[]`) - rust-lang#136724 (Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]`) - rust-lang#136727 (Have a break from review rotation) - rust-lang#136730 (transmutability: fix ICE when passing wrong ADT to ASSUME) - rust-lang#136736 (Small resolve refactor) - rust-lang#136746 (Emit an error if `-Zdwarf-version=1` is requested) r? `@ghost` `@rustbot` modify labels: rollup
…=workingjubilee Document `Sum::sum` returns additive identities for `[]` Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return. Relevant Commit: rust-lang@4908188 Relevant Pull Request: rust-lang#129321 --- The referenced commit causes unintended side effects on presentation layer applications like using Tera templates, for example. I'm not sure what the motivation was behind the original change, but it seems like more discussion should be put into this issue and potentially have that change reverted.
…kingjubilee Rollup of 10 pull requests Successful merges: - rust-lang#136397 (Add a comment pointing to ICE-136223) - rust-lang#136681 (resolve `llvm-config` path properly on cross builds) - rust-lang#136686 (Clean up `HashMap` and `HashSet` docs.) - rust-lang#136694 (Update minifier version to `0.3.4`) - rust-lang#136706 (compiler: mostly-finish `rustc_abi` updates) - rust-lang#136710 (Document `Sum::sum` returns additive identities for `[]`) - rust-lang#136724 (Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]`) - rust-lang#136727 (Have a break from review rotation) - rust-lang#136730 (transmutability: fix ICE when passing wrong ADT to ASSUME) - rust-lang#136736 (Small resolve refactor) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 8 pull requests Successful merges: - rust-lang#136397 (Add a comment pointing to ICE-136223) - rust-lang#136686 (Clean up `HashMap` and `HashSet` docs.) - rust-lang#136706 (compiler: mostly-finish `rustc_abi` updates) - rust-lang#136710 (Document `Sum::sum` returns additive identities for `[]`) - rust-lang#136724 (Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]`) - rust-lang#136727 (Have a break from review rotation) - rust-lang#136730 (transmutability: fix ICE when passing wrong ADT to ASSUME) - rust-lang#136736 (Small resolve refactor) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136710 - JakenHerman:jaken/iterator-docs, r=workingjubilee Document `Sum::sum` returns additive identities for `[]` Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return. Relevant Commit: rust-lang@4908188 Relevant Pull Request: rust-lang#129321 --- The referenced commit causes unintended side effects on presentation layer applications like using Tera templates, for example. I'm not sure what the motivation was behind the original change, but it seems like more discussion should be put into this issue and potentially have that change reverted.
Because the neutral element of
<fNN as iter::Sum>
was changed toneg_zero
, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return.Relevant Commit: 4908188
Relevant Pull Request: #129321
The referenced commit causes unintended side effects on presentation layer applications like using Tera templates, for example. I'm not sure what the motivation was behind the original change, but it seems like more discussion should be put into this issue and potentially have that change reverted.