-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add NaNs, infinities and overflows support to sum #12355
Conversation
|
||
fn samesign(x:f64, y:f64) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style is x: f64
with a space.
Looks pretty good, thanks! |
let mut lo = l; | ||
if hi.is_infinite() { | ||
let mut sign = -1f64; | ||
if hi > 0f64 { sign = 1f64 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be written:
let sign =
if hi > 0f64 { 1f64 }
else { -1f64 };
Spares an alloc in the else
case and a mut
annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no allocation here ;P and LLVM will almost certainly optimise to the same code. But I agree that if hi > 0.0 {1.0} else {-1.0}
would be better.
(Also, @g3xzh, note that you can avoid the verbose/ugly f64
suffix by using a generic 0.0
literal. :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Why is there a distinct |
There is no |
@huonw Then why isn't this part of the stdlib? |
It kinda is in the stdlib here. (It is significantly slower than just straight |
Sure. I think we will want IEEE 754-2008 in |
AFAICT, I don't think IEEE 754 includes an accurate summation algorithm in the spec. |
@huonw and @adrientetar - I would like to read your feedbacks. |
if partials[0] == 0.0 { | ||
let mut tmp_pop = partials.pop(); | ||
if tmp_pop.is_none() { fail!("stats::sum() failure"); } | ||
let mut total_so_far = tmp_pop.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write
let mut total_so_far = partials.pop().expect("Impossible empty vector in Stats.sum");
which does the .is_none
check + fail!
internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. 👍
This needs a rebase too. |
@huonw, 🏁 rebased. |
GitHub is still saying it needs a rebase. You'll probably need to fetch mozilla/rust again. |
@huonw How can you tell? |
@adrientetar github shows committers (and only commiters :( ) in a little box above this comment box. The "Stale" category of the bors queue shows it too (but bors only runs every 5 minutes, so that's on a bit of a delay). |
Yes, please (I'll have one final look over tomorrow morning but I think this is good to go). |
Stats::sum handles NaNs and infinities as elements in the list. In addition to that, it also detects overflows. Note: Stats::sum is using std::vec_ng:Vec to improve its performance.
@huonw - done. |
@huonw , is there a way to debug it without installing a 32bit linux (on a VM)? |
The test definitely passes locally for you? |
That is correct. it passes locally:
|
I guess installing a 32bit linux in a VM would work. (Theoretically you could use one of the distributions with nightly packages to just compile the module with tests directly, rather than doing the full bootstrap.) |
Presumably you could also just cross-compile, ./configure On Sun, Mar 2, 2014 at 10:38 PM, Huon Wilson notifications@github.comwrote:
|
I can't reproduce it.
Any ideas? |
It looks like it failed on the nopt builder. Is your build still optimizing? |
@sfackler - I have no idea. I compile by executing |
Huh, I just ran it locally on real x86 hardware... passes fine. I've got no idea what's up with this. Maybe you could add some |
@huonw lets do it! :) |
I don't really agree with the overflow handling here. It should really just become |
This is just using the same algorithm that Python was using (they now use a bigint based one, iirc), which comes with a proof of correctness. As such, I would suggest that we merge this without significant modification, and defer (considered) adjustments to later pull requests. (I do agree with both of your points though.) (@g3xzh I'll r+ later today, and kill the builds on most bots so that we can just see the results on the 32-bit ones.) |
The exceptions are because I killed those builds because we're investigating this 32-bit failure. The following are still running:
|
And http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/3713/ failed with output:
|
Doesn't make sense. Why is |
Closing due to inactivity, feel free to reopen with a rebase! |
…rds, r=flodiebold Fix inference when pattern matching a tuple field with a wildcard This should fix the following issue: rust-lang/rust-analyzer#12331 * Replaced the `err_ty` in `infer_pat()` with a new type variable. * Had to change the iterator code a bit, to get around multiple mutable borrows of `self` in `infer_pat()`. Also added a test * Also added a test
[`box_default`]: Preserve required path segments When encountering code such as: ```rs Box::new(outer::Inner::default()) ``` clippy would suggest replacing with `Box::<Inner>::default()`, dropping the `outer::` segment. This behavior is incorrect and that commit fixes it. What it does is it checks the contents of the `Box::new` and, if it is of the form `A::B::default`, does a text replacement, inserting `A::B` in the `Box`'s quickfix generic list. If the source does not match that pattern (including `Vec::from(..)` or other `T::new()` calls), we then fallback to the original code. Fixes rust-lang#11927 *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`box_default`]: Preserve required path segments
Stats::sum handles
NaNs
andInfinities
as elements in the list.In addition to that, it also detects overflows.
@huonw - your review, please. :-)
Attempting to fix #11059
(BTW, thanks to @cmr, @sfackler, dybt, @bjz, huon, eibwen for the support on the IRC)