-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Deprecate {f32,f64}::abs_sub. #33664
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
cc @rust-lang/libs This differs to the decision we made in the meeting last week: we decided to just deprecate the function, recommending the use of |
Do we actually know of any contexts in which this operation is used? |
I don't know of any, but it seems unfortunate to deprecate a function and recommend something that is not a true replacement: it's happened before, and people rightly haven't been happy. If people are happy to take this "risk", I'll just remove the new functions in line with what we decided last week, but we didn't think about NaN then. (FWIW, I found some more history about this operation: the |
Sounds reasonable to me! |
/// assert!(abs_difference_x <= f32::EPSILON); | ||
/// assert!(abs_difference_y <= f32::EPSILON); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.10.0")] |
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 feature name won’t work I think.
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.
It compiles, what do you mean?
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.
Ah, @alexcrichton pointed out that make tidy
fails. Thanks @nagisa.
pub fn abs_sub(self, other: f64) -> f64 { | ||
unsafe { cmath::fdim(self, other) } | ||
} | ||
|
||
/// The positive difference of two numbers. | ||
/// | ||
/// * If `self <= other`: `0:0` |
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.
0:0
or 0.0
?
The abs_sub name is misleading: the function actually computes the positive difference (`fdim` in C), not the `(x - y).abs()` that *many* people expect from the name. This function can be replaced with just `(x - y).max(0.0)`, mirroring the `abs` version, but this behaves differently with NAN: `NAN.max(0.0) == 0.0`, while `NAN.positive_diff(0.0) == NAN`. People who absolutely need that behaviour can use the C function directly and/or talk to the libs team (we haven't encountered a concrete use-case for this functionality). Closes rust-lang#30315.
Updated to just deprecate the functions, including calling for people to file issues describing their use-cases for positive difference if they have them. |
(Alternatively, I could just point them to #30315 or this PR and ask for a comment?) |
The libs team discussed this PR during triage yesterday and the conclusion was:
|
Deprecate {f32,f64}::abs_sub. The abs_sub name is misleading: the function actually computes the positive difference (`fdim` in C), not the `(x - y).abs()` that *many* people expect from the name. This function can be replaced with just `(x - y).max(0.0)`, mirroring the `abs` version, but this behaves differently with NAN: `NAN.max(0.0) == 0.0`, while `NAN.positive_diff(0.0) == NAN`. People who absolutely need that behaviour can use the C function directly and/or talk to the libs team (we haven't encountered a concrete use-case for this functionality). Closes #30315.
The abs_sub name is misleading: the function actually computes the
positive difference (
fdim
in C), not the(x - y).abs()
that many people expectfrom the name.
This function can be replaced with just
(x - y).max(0.0)
, mirroringthe
abs
version, but this behaves differently with NAN:NAN.max(0.0) == 0.0
, whileNAN.positive_diff(0.0) == NAN
. People who absolutelyneed that behaviour can use the C function directly and/or talk to the libs
team (we haven't encountered a concrete use-case for this functionality).
Closes #30315.