-
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
abs_sub is strangely named #30315
Comments
I disagree |
Note that |
@ranma42 EDIT: This comment is stupid and wrong and horribly embarrassing |
@jFransham abs(-1) is 1, but max(-1, 0) is 0. Did you mean abs(x) = max(x, -x)? In any case, this playground demonstrates what @ranma42 stated. |
Good point, I guess |
I think one of the following names would fit better:
|
Monus as pointed out by sp3d on IRC. The page also mentions these names the operation is referred to:
|
Most of the methods name the result (e.g. |
The libs team discussed this issue during triage the other day and the conclusion was that this is so confusingly named and sparingly used that we should probably just document it. The deprecation message can indicate:
|
After the meetings, I realised this isn't quite true: |
I just wasted somewhere between 3-4 hours over the last day debugging my game, thinking that this was equivalent to I'm definitely in support of deprecation and renaming. |
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.
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.
`x.abs_sub(y)` is defined ([confusingly](rust-lang/rust#30315)) as `max(x-y, 0)`, not `abs(x-y)`. This wasn't caught in tests since `t_x - t_y` in [src/algorithm/intersects.rs:48](https://github.com/georust/rust-geo/blob/master/src/algorithm/intersects.rs#L48) is positive in all of the given examples.
120: Incorrect usage of `abs_sub` r=frewsxcv `x.abs_sub(y)` is defined ([confusingly](rust-lang/rust#30315)) as `max(x-y, 0)`, not `abs(x-y)`. This wasn't caught in tests since `t_x - t_y` in [src/algorithm/intersects.rs:48](https://github.com/georust/rust-geo/blob/master/src/algorithm/intersects.rs#L48) happens to be positive in all of the given examples so I've added a new example where `t_x - t_y` is negative.
The C name is
fdim
, and the operation is described as "positive difference" by e.g. the C function's man page, which isn't really suggested by "abs_sub" at all.The text was updated successfully, but these errors were encountered: