-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Added next_up and next_down for f32/f64. #88728
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
In the RFC you mention “Repeatedly calling next_up on a negative number will iterate over all values above it, with the exception of +0.0, only -0.0 will be visited.” I think this point would be good to make explicitly in the documentation of these functions — it is a place where the two goals “exhaust the space of float-representable numbers” and “move along the number line in the smallest nonzero step” differ, and it's worth mentioning this to, if nothing else, prompt the programmer to think about which thing they're doing and whether the function's inherent behavior is correct for their use case. |
👍 to having these. I think we should explicitly mention that these are expected to match IEEE's I don't think we'll find any name that's substantially better, so sticking with precedent seems best. (And we can add another thing with different names if there ends up being a desire to have something that doesn't follow IEEE exactly, like if there were one that visited every bit sequence.) |
Everything looks good and I don't think I have anything to add other than to say thank you for the wonderful PR! I'm gonna go ahead and merge this since it's all nightly only and then I'll start an FCP on the RFC since it's already there, might as well not waste it. @bors r+ |
📌 Commit 4dd9b85 has been approved by |
Added next_up and next_down for f32/f64. This is a pull request implementing the features described at rust-lang/rfcs#3173.
Added next_up and next_down for f32/f64. This is a pull request implementing the features described at rust-lang/rfcs#3173.
Some test were failing in a rollup, looks like it was caused by this PR: #90178 (comment) @bors r- |
☔ The latest upstream changes (presumably #90314) made this pull request unmergeable. Please resolve the merge conflicts. |
So investigating why my pull request failed, I'm not sure that it's my fault. This fails on i586: f32::from_bits(0x7F955555).to_bits() == 0x7F955555 This violates the standard library guarantees, which say that It's not my code that failed either way, it's just that the way I wrote the testcase assumes let nan0 = f32::NAN.to_bits();
let nan1 = f32::NAN.to_bits() ^ 0x002a_aaaa;
let nan2 = f32::NAN.to_bits() ^ 0x0055_5555;
assert_eq!(f32::from_bits(nan0).next_down().to_bits(), nan0);
assert_eq!(f32::from_bits(nan1).next_down().to_bits(), nan1);
assert_eq!(f32::from_bits(nan2).next_down().to_bits(), nan2); |
NANs are always a bit weird, and pre-i686 floats are particularly annoying. You might be interested in the conversations in #73328 But honestly for now I'd just say |
4dd9b85
to
6f543ee
Compare
…ottmcm Added next_up and next_down for f32/f64. This is a pull request implementing the features described at rust-lang/rfcs#3173.
Still failing in ci I guess: #91983 (comment) @bors rollup=never r- |
I don't know how it was marked to be ready to merged since we knew it was failing two weeks ago, sorry for wasting your time. The problem is that x87 floating point is very problematic for this set of functions. At first I thought it was just NaN bits not being preserved, but it appears that it's also flushing denormals to zero, not just when doing arithmetic operations, but also when passing values through function boundaries. I think I'll disable testing on x87 floating point platforms for now and indeed add an unresolved question to the tracking issue. I honestly don't know what to do with this platform. |
Oh strange, you're right I didn't see that. |
/// - if `self` is [`MAX`] or [`INFINITY`], this returns [`INFINITY`]; | ||
/// - otherwise the unique least value greater than `self` is returned. | ||
/// | ||
/// The identity `x.next_up() == -(-x).next_down()` holds for all `x`. When `x` |
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 is technically not true for x = NAN
.
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 not?
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.
Oh I think I see what you're getting at, ==
here is to be understood as a bitwise / definition equality, not floating point comparison where NaN != NaN
.
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.
Should I update this doc comment to say "for all non-NaN x
"? Or maybe reword it to "x.next_up()
is equivalent to -(-x).next_down()
for all x
" to prevent confusion with ==
failing for NaNs?
ping from triage: When it's ready for review send a message containing |
@orlp any updates on this? |
@Dylan-DPC I think I've been procrastinating on this because I don't see a good solution. Today I'll update the tracking issue with the unresolved question on what to do with x87, disable the testing for that platform for now and push my changes. |
I've posted the unresolved question to the tracking issue: #91399 (comment) Should I wait with asking a review for this until the unresolved question is resolved or do it now @JohnCSimon ? |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #94546) made this pull request unmergeable. Please resolve the merge conflicts. |
@orlp - if you think it's ready for review, go ahead and mark it ready for review. I'm just doing PR triage. |
Add next_up and next_down for f32/f64 - take 2 This is a revival of rust-lang#88728 which staled due to inactivity of the original author. I've address the last review comment. --- This is a pull request implementing the features described at rust-lang/rfcs#3173. `@rustbot` label +T-libs-api -T-libs r? `@scottmcm` cc `@orlp`
Add next_up and next_down for f32/f64 - take 2 This is a revival of rust-lang/rust#88728 which staled due to inactivity of the original author. I've address the last review comment. --- This is a pull request implementing the features described at rust-lang/rfcs#3173. `@rustbot` label +T-libs-api -T-libs r? `@scottmcm` cc `@orlp`
Add next_up and next_down for f32/f64 - take 2 This is a revival of rust-lang/rust#88728 which staled due to inactivity of the original author. I've address the last review comment. --- This is a pull request implementing the features described at rust-lang/rfcs#3173. `@rustbot` label +T-libs-api -T-libs r? `@scottmcm` cc `@orlp`
Add next_up and next_down for f32/f64 - take 2 This is a revival of rust-lang/rust#88728 which staled due to inactivity of the original author. I've address the last review comment. --- This is a pull request implementing the features described at rust-lang/rfcs#3173. `@rustbot` label +T-libs-api -T-libs r? `@scottmcm` cc `@orlp`
This is a pull request implementing the features described at rust-lang/rfcs#3173.