[libc-commits] [libc] [libc][math][c23] Fix bounds checking in {, u}fromfp{, x}* (PR #86892)

via libc-commits libc-commits at lists.llvm.org
Wed Mar 27 20:50:05 PDT 2024


================
@@ -247,6 +247,11 @@ round_using_current_rounding_mode(T x) {
 template <bool IsSigned, typename T>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
 fromfp(T x, int rnd, unsigned int width) {
+  using StorageType = typename FPBits<T>::StorageType;
+
+  constexpr StorageType EXPLICIT_BIT =
+      FPBits<T>::SIG_MASK - FPBits<T>::FRACTION_MASK;
+
   if (width == 0U)
     return FPBits<T>::quiet_nan().get_val();
----------------
lntue wrote:

I just re-read section F.10.6.10 and F.10.6.11 in N3096, it looks like we will need to raise `FE_INVALID` for those out-of-range cases.

https://github.com/llvm/llvm-project/pull/86892


More information about the libc-commits mailing list