[PATCH] D66836: [libc++] Add `__truncating_cast` for safely casting float types to integers
Steve Canon via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 28 14:11:37 PDT 2019
scanon added a comment.
In D66836#1649846 <https://reviews.llvm.org/D66836#1649846>, @zoecarver wrote:
> > Dead link.
>
> Here: https://godbolt.org/z/AjBHYq
Yes, conversion of `numeric_limits<long long>::max` to `double` rounds to a value out of range for `long long`. That's not what I'm talking about. Very specifically, in this line:
`if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY))`
`_MaxVal`, by construction, is representable both as `_RealT` and as `_IntT`, so the static_cast does not change the value (so the rounding demonstrated in your godbolt link doesn't create a bug). `a >= nextafter(b, INFINITY)` is equivalent to `a > b` for any finite floating-point `a` and `b`. So this condition can simply be `if (__r > static_cast<_RealT>(_MaxVal))`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66836/new/
https://reviews.llvm.org/D66836
More information about the cfe-commits
mailing list