[libc-commits] [libc] [libc][math][c23] Add f16divf C23 math function (PR #96131)

via libc-commits libc-commits at lists.llvm.org
Mon Jun 24 13:48:16 PDT 2024


================
@@ -179,10 +182,18 @@ template <size_t Bits> struct DyadicFloat {
       output_bits_t clear_exp = static_cast<output_bits_t>(
           output_bits_t(exp_hi) << FPBits<T>::SIG_LEN);
       output_bits_t r_bits = FPBits<T>(r).uintval() - clear_exp;
+
       if (!(r_bits & FPBits<T>::EXP_MASK)) {
         // Output is denormal after rounding, clear the implicit bit for 80-bit
         // long double.
         r_bits -= IMPLICIT_MASK;
+
+        // TODO: IEEE Std 754-2019 lets implementers choose whether to check for
+        // "tininess" before or after rounding for base-2 formats, as long as
+        // the same choice is made for all operations. Our choice to check after
+        // rounding might not be the same as the hardware's.
+        if (round_and_sticky)
+          raise_except_if_required(FE_UNDERFLOW);
----------------
lntue wrote:

Then maybe we should refactor `operator T()` to a separate `cast<>` or `to<>` template function, with another boolean `SET_EXCEPTION/SET_UNDERFLOW` template parameter defaulted to `false`, and under that flag, set errno in addition to raise except.  The the default `operator T()` will just call to that template with default `SET_EXCEPTION/SET_UNDERFLOW` to preserve current behavior?

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


More information about the libc-commits mailing list