Skip to content

Commit

Permalink
Rollup merge of rust-lang#56857 - tbu-:pr_doc_abssub, r=zackmdavis
Browse files Browse the repository at this point in the history
Fix a small mistake regarding NaNs in a deprecation message

`max` on floats returns the other argument if one of them is NaN, which
would be `0.0` in this case. This is unlike the C functions `fdim` and
`fdimf` which return NaN if either of their arguments is NaN.

https://doc.rust-lang.org/1.31.0/std/primitive.f32.html#method.max
https://en.cppreference.com/w/c/numeric/math/fdim
  • Loading branch information
Centril authored Dec 16, 2018
2 parents a777754 + 967b1fc commit cee0bdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ impl f32 {
#[inline]
#[rustc_deprecated(since = "1.10.0",
reason = "you probably meant `(self - other).abs()`: \
this operation is `(self - other).max(0.0)` (also \
this operation is `(self - other).max(0.0)` \
except that `abs_sub` also propagates NaNs (also \
known as `fdimf` in C). If you truly need the positive \
difference, consider using that expression or the C function \
`fdimf`, depending on how you wish to handle NaN (please consider \
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ impl f64 {
#[inline]
#[rustc_deprecated(since = "1.10.0",
reason = "you probably meant `(self - other).abs()`: \
this operation is `(self - other).max(0.0)` (also \
this operation is `(self - other).max(0.0)` \
except that `abs_sub` also propagates NaNs (also \
known as `fdim` in C). If you truly need the positive \
difference, consider using that expression or the C function \
`fdim`, depending on how you wish to handle NaN (please consider \
Expand Down

0 comments on commit cee0bdd

Please sign in to comment.