-
Notifications
You must be signed in to change notification settings - Fork 158
Description
/// The positive difference of two numbers.
///
/// Returns `zero` if the number is less than or equal to `other`, otherwise the difference
/// between `self` and `other` is returned.
fn abs_sub(&self, other: &Self) -> Self;When I hear abs_sub, I expect it to be |a-b|. At the very least, I think that the abs_sub function could be created as some composition or combination of the abs function and the sub function, but it appears that abs_sub is more of a saturating sub or a clamped sub (i.e. max(0, a-b))
Furthermore, the documentation seems to contradict itself -- "The positive difference of two numbers" is not the same as "zero if the number is less than equal to other". For example, with a=3 and b=5, I would expect the positive difference to mean the difference a - b = 3 - 5 = -2, but now positive = 2.
And finally, if a Type implements Num (which includes NumOps, which includes Sub) and it implements Signed, then abs_sub will always have the same form of
fn abs_sub(&self, other: &Self) -> Self {
tmp = self - other;
if tmp.is_negative {
Self::zero()
}
tmp
}I suggest either documenting abs_sub as meaning |a-b|, and providing an implementation or removing it entirely.