Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libstd/f32.rs
Outdated
There was a problem hiding this comment.
Perhaps an example of NAN input giving NAN output?
src/libsyntax/feature_gate.rs
Outdated
There was a problem hiding this comment.
No need for the feature gate in code for lib changes; the attribute is sufficient.
src/libstd/f32.rs
Outdated
| } | ||
|
|
||
| /// Returns max if self is greater than max, and min if self is less than min. | ||
| /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. |
There was a problem hiding this comment.
Should this be "is NaN" and not "equals NaN"? Nothing is equal (as in ==) to NaN, not even NaN.
src/libstd/f64.rs
Outdated
| } | ||
|
|
||
| /// Returns max if self is greater than max, and min if self is less than min. | ||
| /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. |
|
Thanks for the PR! We’ll periodically check in on it to make sure that @BurntSushi or someone else from the team reviews it soon. |
src/libcore/cmp.rs
Outdated
| } | ||
|
|
||
| /// Returns max if self is greater than max, and min if self is less than min. | ||
| /// Otherwise this will return self. Panics if min > max. |
There was a problem hiding this comment.
I think this should follow our doc formatting conventions, no? I think we usually have a panics header for documenting panic'ing conditions.
| } else { | ||
| self | ||
| } | ||
| } |
There was a problem hiding this comment.
Could you format this in a way that is consistent with the surrounding code? (Do we do rustmt on this stuff yet?)
src/libstd/f32.rs
Outdated
| } | ||
|
|
||
| /// Returns max if self is greater than max, and min if self is less than min. | ||
| /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. |
There was a problem hiding this comment.
Needs panic header for here too.
src/libstd/f64.rs
Outdated
| } | ||
|
|
||
| /// Returns max if self is greater than max, and min if self is less than min. | ||
| /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. |
BurntSushi
left a comment
There was a problem hiding this comment.
This mostly looks good, but have some nits! I guess this should also technically wait to merge until the RFC has been merged?
|
r? @BurntSushi Yeah this will have to wait for the RFC to be merged. I mostly opened this early since the implementation was so straightforward. |
BurntSushi
left a comment
There was a problem hiding this comment.
Oh, and could you also add some unit tests for the panic conditions? Thanks!
|
@bors r=burntsushi |
|
📌 Commit b762283 has been approved by |
|
@aturon @BurntSushi That didn't seem to work :/ |
|
@bors rollup |
Add clamp functions Implementation of clamp feature: Tracking issue: rust-lang#44095 RFC: rust-lang/rfcs#1961
| /// Panics if min > max, min is NaN, or max is NaN. | ||
| #[unstable(feature = "clamp", issue = "44095")] | ||
| #[inline] | ||
| pub fn clamp(self, min: f64, max: f64) -> f64 { |
There was a problem hiding this comment.
I'm a Rust beginner, but I think, this should also work. I don't like the mut.
if x < min { min }
if x > max { max }
else { self }There was a problem hiding this comment.
That was the original implementation. This specific code pattern was chosen because it yields a highly efficient assembly implementation. This was actually the source of quite a bit of conversation before we settled on this.
There was a problem hiding this comment.
Holy caroly (this is actually no real word, but it rhymes)!
Add clamp functions Implementation of clamp feature: Tracking issue: rust-lang#44095 RFC: rust-lang/rfcs#1961
|
This broke Servo and Pathfinder. See servo/app_units#37 |
Implementation of clamp feature:
Tracking issue: #44095
RFC: rust-lang/rfcs#1961